Skip to content

feat(rust): the Rust port - #26

Merged
4matic merged 21 commits into
mainfrom
feat/rust-port
Nov 11, 2026
Merged

4matic merged 21 commits into
mainfrom
feat/rust-port

Conversation

@4matic

@4matic 4matic commented Nov 11, 2026

Copy link
Copy Markdown
Owner

The third port: a Rust crate in rust/, to be published as trackparse on crates.io. It passes every shared fixture and gives the same JSON as the JS reference.

The crate

  • One module per js/src file (single tracks R0–R12, tracklists R13), same rule IDs in comments.
  • One required dependency (unicode-normalization ≥ 0.1.26); serde behind a feature; no unsafe; clippy denies unwrap, expect, panic and indexing in src/; MSRV 1.74.
  • API: parse, parse_with, parse_artists, format_track, normalize, all_artists, Parser; tracklist::{parse_tracklist, apply_edits, Edit, …}; to_json() on every output type gives the spec's JSON; option structs with chained setters.
  • Generated from the JS engine so results don't depend on the compiler's Unicode version: general category L / Lu tables and a lowercase table with the final-sigma rule (rust/scripts/gen_data.mjs, with --check).

Evidence

  • Fixtures: 13,130 / 13,130, empty skip list, on stable and 1.74.
  • scripts/compare-ports.mjs now compares JS with Python and with Rust: 0 differences each on all 13,130 cases.
  • Differential runs against JS during the port: 0 differences on ~500,000 random single-track cases, 290,000 random tracklists with edits, the private corpus, and every Unicode code point through four functions.
  • Independent pre-publish review: 480,000 hostile inputs in a debug build, 0 panics. Its findings are fixed here (a line-number type, the dependency bound, sealing the JSON trait, serde edge cases, a quadratic dedup made near-linear, missing derives, property tests for single tracks).

Docs

  • Every example on the site has JavaScript, Python and Rust tabs (56 groups); all 57 Rust blocks were compiled and run against the final crate. Reference pages, ports, testing, contributing, the root README and AGENTS.md cover the third port. The playground's code panels can show Rust.
  • rust/README.md is the crates.io page; its 17 examples are doc tests.

CI and release

  • rust.yml: fmt, clippy, tests on stable and 1.74 (--locked), package dry run, and the JS-vs-Rust comparison.
  • release-please: rust joins the linked versions (rust-vX.Y.Z). publish-crates uses crates.io trusted publishing and is gated on the repository variable CRATES_PUBLISH, because the first publish of a new crate has to be done by hand. spec.yml checks four versions.

Known and documented

  • NFC/NFD follow unicode-normalization (Unicode 18); Node 24 has Unicode 17, so 32 new combining marks can order differently.
  • Before the first crates.io release the docs give the git install command.

… harness

rust/ is now a Cargo package: data.rs and the Unicode L / Lu tables are generated from spec/data
and the JS engine (scripts/gen_data.mjs, with --check), types mirror the schema with to_json(),
and tests/fixtures.rs runs every shared fixture through trackparse::wire::call with the README
matcher, xfail/ambiguous/skip handling and a conformance report. The parser is a stub: 0 / 13130.
…with it

rustfmt.toml sets max_width 100 and use_small_heuristics Max, the width the JS and Python
ports use. json.rs and tests/fixtures.rs are reformatted; the generated data.rs and
unicode_tables.rs are skipped so gen_data.mjs stays the only writer.
…_track, normalize, Parser)

Modules mirror js/src one to one (words, digits, normalize, mode, scanner, prefix, classify,
separator, artists, credits, title, assemble, format, tables, context, parser, options) with
the same rule IDs in comments.

- Public API: parse / parse_with, parse_artists / parse_artists_with, format_track /
  format_track_with, normalize, all_artists, Parser, and typed ParseOptions, FormatOptions and
  KeywordOptions with builder-style setters.
- wire::call answers parse, parseArtists, format and normalize; loose JSON options are resolved
  with the JS fallbacks (unknown mode, splitAnd, non-object keywords, Object.entries key order).
- Offsets are UTF-16 units and the knownArtists window counts UTF-16 units, as in JS; letter and
  uppercase tests use the generated L / Lu tables; keyword keys are trimmed like JS trim().
- The internal ListParser (probe / finish with the list-context flag) is in place for R13.
- Unit tests for the R0 primitives use values dumped from js/src/words.ts
  (scripts/dump_primitives.mjs writes tests/data/primitives.json).

Every non-tracklist fixture passes (11,914 of 13,130; the rest are parseTracklist / applyEdits).
tests/api.rs checks that the typed API (options, format options, Parser) gives the same JSON
as wire::call, that bad loose options fall back as in JS, and that 10,000-code-point inputs
finish quickly in every mode. examples/dump.rs reads JSONL cases on stdin and writes one JSON
result per line through wire::call, for a differential run against js/dist.
rust.yml runs fmt, clippy, every fixture and the package dry run on stable and on the MSRV
(1.74), plus a job that diffs the full output of every fixture input against the built JS
package. compare-ports.mjs now compares JS with each other port (--only=python / --only=rust).
Port of js/src/tracklist to rust/src/tracklist, one module per JS file: line
split, time scanner, emphasis markers, kinds, bare positions, warnings with the
out-of-order suggestion search, and apply_edits. wire::call now answers
parseTracklist and applyEdits; typed Edit values go through the same loose-JSON
path as the fixtures.

- json: numbers are written as JS Number::toString does (1e+21, 1e-7, -0 as 0)
- fixtures harness: 1e999 reaches the crate as infinity
- tests: typed tracklist API vs the wire, R13.11 properties and time ceilings
- LICENSE copied into the crate for cargo package

All 13,130 shared fixtures pass with an empty skip list.
… compiler's Unicode version

str::to_lowercase follows the toolchain: on Rust 1.74, 55 letters lowercased differently
from the JS reference. gen_data.mjs now writes the toLowerCase() mapping and the Cased and
Case_Ignorable ranges for the final-sigma rule into unicode_tables.rs; words.rs reads them.
Checked against JS over every scalar value and 160,000 strings around sigma, on 1.74 and stable.
The JS / Python switch gains Rust in both code panels. The generated Rust is a whole program (use, fn main) built from the option builders and the Edit constructors; codeHtml has an rs branch.
…oject pages

All 56 tab groups are JavaScript, Python, Rust. Every Rust example was compiled and run against the crate. cargo in the install switch (it wraps on phones), the Rust row and findings on the ports page, three ports in testing and contributing.
README: ports table, install, a Rust quick start, At a glance. AGENTS.md: repo map and commands for rust/, the trilingual tab template, rust.yml, the hazards the Rust port found, definition of done.
- serde (optional): Serialize and Deserialize on every output type, the options and Edit, with
  the spec's keys; serde_json::to_string(&x) is the text of x.to_json(). A test asserts it over
  every fixture input, and that options and edits read from JSON give what the JSON door gives.
- to_json() is an inherent method on every output type; ToJson stays for generic code.
- Enums: FromStr (UnknownName), NAMES, Default on the option enums; #[non_exhaustive] on the
  enums that can grow, on the option structs and on Edit.
- Edit constructors: set_time, shift, shift_from, shift_lines, sort_by_time, set_rest, insert,
  delete.
- The types and options modules are private; everything is exported from the crate root and
  from trackparse::tracklist. json::Json implements Display.
- Crate docs and a runnable example on every public function and type; #![warn(missing_docs)].
Install, quick start, the API with options tables, JSON and serde, modes, tracklists, how it
is tested and the minimum Rust version. Every Rust example is a doc test (cargo test
--all-features runs the README). docs.rs builds with all features.
…o publish job

rust joins js, spec and python in the linked versions (Cargo.toml and SPEC_VERSION in data.rs
are bumped by the release PR). publish-crates uses crates.io trusted publishing and runs only when
the repository variable CRATES_PUBLISH is "true": the first publish of a new crate has to be done
by hand before a trusted publisher can be configured. spec.yml checks all four versions match.
…ase setup

Type listings follow the real definitions (ParseOptions field order, #[non_exhaustive] on
the option structs and Edit). AGENTS.md and the Ports page describe the rust release-please
component, the rust-vX.Y.Z tag, the CRATES_PUBLISH gate and the first publish by hand.
…credits

Each credit list keeps its remaining names in an ordered set, so the R7.6 joiner hand-over
is a lookup, not a scan of every entry. Output is unchanged: a unit test compares it with
the plain algorithm on 20,000 random credit lists, and compare-ports reports 0 differences.
- EditWarning.line is Option<usize>, like every other line number (saturating from the JS
  number the edit ran on); to_json() and the wire still print what JavaScript prints.
- unicode-normalization >= 0.1.26: older releases have older Unicode tables.
- Json is #[non_exhaustive] and ToJson is sealed.
- serde: numbers share the to_json() writer (digits of 2^53 and more as JavaScript prints
  them, lines above 2^53 as doubles), non-finite seconds are null and read back as NaN,
  keyword maps are written and read without repeated keys.
- Hash on the Eq output and option types, Clone on Parser, doc(cfg) for docs.rs.
- The guarantees no longer claim linear time; they say what the tests check.
- tests/properties.rs: the single-track invariants of SPEC.md on generated strings, the
  10,000-code-point ceiling and a 40k/160k scaling check.
…README

compare-ports compares the complete JSON output, not bytes.
@4matic
4matic merged commit 1ee0796 into main Nov 11, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant