/rewrite-rs-skills:port-from-typescriptfrom rewrite-rs-skills
Maps TypeScript/JavaScript runtime semantics to Rust constructs, covering napi-rs and wasm-bindgen boundaries. Use when porting JS code to Rust, replacing hot modules with native addons or WebAssembly.
Ships in rewrite-rs-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
This skill maps the JavaScript runtime to Rust and owns the two
boundaries, napi-rs and wasm-bindgen. The parity contract, the
phases, and the anti-patterns are /port-to-rust. TypeScript and
JavaScript are one skill because they are one runtime: the types
are erased before anything runs, so the mapping is the same and
the annotations are evidence about intent, not guarantees about values.
/port-to-rust names three end states, and this skill asks rather than
assumes.
| End state | In TypeScript and JavaScript terms | Binding layer |
|---|---|---|
| A. Replacement | A Rust binary or crate takes over; nothing imports it from JavaScript afterwards, and the seam is the CLI, route, or worker that already exists | Neither napi-rs nor wasm appears |
| B. Rust core, the npm package is the product | The module keeps its name and its exported signatures; the engine underneath becomes Rust | Permanent public surface — signatures, error types, prebuilds per platform, semver |
| C. Scaffold | The port ends standalone, but JavaScript calls the Rust module while the migration is under way | Temporary, and deleted at cut-over |
Under B or C: Node, Deno, and Bun take a native addon through
napi-rs; browsers and edge runtimes take WebAssembly through
wasm-bindgen. They are not interchangeable: wasm has no threads by
default, no filesystem, a serialization cost at every call, and a
hard cap on what crates will compile. Choosing the wrong one is a
rewrite, not a refactor. Mechanics in BOUNDARY.md.
| Trap | What actually differs |
|---|---|
Every number is an f64 | There is no integer type. Above 2⁵³ values lose precision silently, and bitwise operators coerce to i32 first — so x | 0 is a documented truncation the port must reproduce or deliberately drop. Decide per field: i64, f64, or i32, and record which in the contract |
| Two kinds of absent | undefined and null are distinct, and most codebases use both without a rule. Rust has one Option, so each field needs a decision, and JSON round-tripping makes it observable — serde must be told whether a missing key and a null key are the same thing |
| Sorting | Array.prototype.sort with no comparator sorts by UTF-16 string conversion, so [10, 9].sort() is [10, 9]. A port that uses a numeric sort produces a different, better, and non-parity result |
| Regex | JavaScript regexes use backtracking and support lookaround and backreferences; the regex crate does not. Any source pattern using them needs a different crate or a restructured matcher, and this is found at port time, not at review time |
| Exceptions carry anything | throw accepts any value, and catch receives it untyped. Mapping to Result means naming the error cases the source never named — /rust-errors — and the ones that were thrown from library code are the ones no test covers |
MAPPING.md holds the full table; a mapping row is a starting
point, not a rewrite rule. Read the runtime values, not the
annotations: the type was erased before anything ran, so any, an
as cast, and an unchecked JSON boundary are unknown input.
/type-driven-designA discriminated union with a kind field is a Rust enum, and
translating it is where a TypeScript port stops reading like
TypeScript. A non-discriminated union (string | number) is a
design question the source deferred and the port must answer.
Structural typing maps to a trait only with several implementations;
an interface with one implementing type is a struct.
Objects carry the same judgment: a plain object with known keys is
a struct; Record<string, T> with a dynamic key set is a
HashMap; Map preserves insertion order where HashMap does not,
so ordered iteration means IndexMap or BTreeMap. Getting this
wrong shows up as reordered JSON output, which is a contract question.
Jest or Vitest cases are characterization input, not the parity
contract. JavaScript suites are especially thin on the coercion
edges — "", 0, NaN, undefined versus a missing key — exactly
where a port narrows behaviour. Harness shapes are /rust-testing.
Single-threaded execution meant shared mutable state was safe by
construction; in Rust the same structure raises Send/Sync
questions, and the honest answer is often that the state should
not have been shared. async maps to tokio — /async-rust —
the shape differs: a JavaScript Promise is eager, a Rust future is
lazy until awaited, so code that fired a promise and did not await
it did run, and its Rust translation does not.
cargo test --all-features
cargo clippy --all-targets --all-features # add -- -D warnings only if the target repo has no lint config
npm test # the existing suite still passes against the module being replaced
npm run build && node -e "require('./index.node'); ..." # end states B and C only — or the wasm equivalent, from the JS side
Under end state A the last line does not exist and the differential harness runs process-to-process; say so rather than leaving a command that does not apply.
Then the differential run with its denominator, plus the
language-specific corpus requirement: at least one case per trap —
a number above 2⁵³, a null where undefined also occurs, an
unsorted numeric array, a regex input that used lookahead, and a
thrown non-Error value.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
TypeScript, JavaScript, Rust, Node, Deno, Bun
typescript-to-rust, javascript-to-rust, napi-rs, wasm-bindgen, porting, migration
28 skills in this plugin
/async-rustWrite correct async Rust — runtime choice, Send and Sync bounds, cancellation safety, blocking work inside async contexts, and shared state across tasks. Use when writing or reviewing async code, when a future is held across an await point, when the user hits a Send bound error on a spawned task, when a runtime stalls or deadlocks, or when the user asks about tokio, select!, or spawn_blocking./idiomatic-rustWrite Rust that reads like Rust — iterator pipelines over index loops, From/Into over ad-hoc converters, derives over hand-written impls, newtypes over bare primitives. Use when writing new Rust, when reviewing Rust that reads like a translation from another language, when reaching for a classic design pattern (strategy, command, visitor) or a try/finally cleanup in Rust, when naming a constructor, accessor, iterator, or error type, or when the user asks how to make Rust code more idiomatic or less repetitive./ownership-not-cloneUse ownership and borrowing instead of reaching for clone, Rc, RefCell, or Arc<Mutex<_>> to silence the borrow checker. Every clone must be explainable. Use when code clones to make an error go away, when a borrow-checker fight is being resolved by copying data, when reviewing Rust dense with .clone() or Rc<RefCell<_>>, or when the user asks whether a clone is necessary./port-from-cPort C into Rust — recovering the ownership, lifetime, nullability, and length that C never recorded, mapping pointers to references and slices, tag-plus-union to enums, return codes and errno to Result, and linking Rust into the existing build with bindgen and cbindgen. Use when porting, rewriting, or migrating C, a C library, firmware, or a C application into Rust, when replacing C modules one at a time behind the existing build, or when the user asks how a C construct such as malloc, a char pointer, a union, or a preprocessor macro translates to Rust./port-from-cppPort C++ into Rust — RAII and smart pointers onto ownership, templates onto generics and traits, exceptions onto Result, the STL onto Rust collections, and the traps (move semantics, implicit conversions, undefined behaviour, iterator invalidation). Use when porting, rewriting, or migrating C++, a C++ library, or a C++ application into Rust, when replacing a C++ module with Rust behind the existing build, or when the user asks how a C++ construct such as unique_ptr, shared_ptr, a template, or an STL container translates to Rust./port-from-goPort Go into Rust — goroutines and channels onto tasks and async, interfaces onto traits, error values onto Result, and the value-semantics traps (zero values, integer wraparound, slice aliasing, nil). Use when porting, rewriting, or migrating Go, Golang, a Go service, or a Go CLI into Rust, when replacing a Go component with a Rust one behind the same interface, or when the user asks how a Go construct translates to Rust.npx claudepluginhub rewrite-rs/skills --plugin rewrite-rs-skillsOther plugins' skills for the same job