Catalogue / rust-anything
rust-anything
MITSignedPort TypeScript/JavaScript, Python, C, Go, Ruby or Java to Rust with the rust-anything CLI or MCP tools, from one hot function up to a whole app rewritten as a pure Rust app - profile, plan, bridge one unit at a time, record the original's behavior, port, diff, bench, shadow and gate; batch hot loop…--- name: rust-anything description: Port TypeScript/JavaScript, Python, C, Go, Ruby or Java to Rust with the rust-anything CLI or MCP tools, from one hot function up to a whole app rewritten as a pure Rust app - profile, plan, bridge one unit at a time, record the original's behavior, port, diff, bench, shadow and gate; batch hot loops so they run in Rust on all cores. Use when asked to rewrite, port or migrate code or an app to Rust, to plan such a migration, or to make slow code faster with Rust. ---
Migration to Rust with rust-anything
rust-anything gives you ground truth; you write the Rust. Port one unit at a time, even when the goal is the whole app, and call a port done only when gate passes.
Whole app to a pure Rust app (the user wants the app rewritten in Rust, with the original kept only as reference): read whole-app.md first and follow it. It grills the user on the decisions, researches the dependencies, records the whole app, puts a Rust front door in front of the original, runs the steps below for every unit, then lifts the app to a standalone Rust binary (or, for a library, one pure Rust crate). CLIs, HTTP servers and libraries.
Languages: TypeScript/JavaScript, Python, C, Go, Ruby, Java. The language is detected; --lang overrides it. The steps are the same everywhere; only the bridge differs (napi-rs or wasm for TS, PyO3, a C ABI, cgo, a magnus extension, JNI), and the original's callers keep their API. For PHP: analyze, and for a whole app app record, app replay and app front-door (CLIs, and servers run with php -S 127.0.0.1:{port} router.php); bridge does not take PHP units yet, so tell the user before planning a PHP port past the front door. C# works the same way: record a built app (dotnet out/app.dll, servers with --urls http://127.0.0.1:{port}); bridge does not take C# units yet.
Tools: the rust-anything CLI, or the same steps as MCP tools (rust-anything mcp): go, profile, analyze, bridge, refresh, record, build, diff, bench, shadow, gate, enable, disable, report, and for a whole app app_record, app_replay, app_front_door, app_wire, app_lift. If the MCP tools are not available, use the CLI; if rust-anything is not installed, ask the user to install it (cargo install rust-anything) and run rust-anything setup, then restart the agent. When a step fails because a runtime, the agent setup or the MCP server is missing or out of date, run rust-anything doctor: it checks each one and prints the command that fixes it.
Only the slow part: go
When the user wants one slow command faster rather than a migration, go runs steps 0 to 5 for the top hot function in one call:
rust-anything go -- python3 app.py # profile, bridge, record, write rust/<fn>-rs/TASK.md # port src/port.rs as TASK.md says (build, diff, gate), then the same command again: rust-anything go -- python3 app.py # build, diff, gate, and enable when all pass
It picks the outermost exported function of a portable unit that takes arguments, batched where profile advises it (--function picks another), and records generated cases plus the calls the workload makes. You are the agent: port only that function, and do not pass --agent (that hands the port to another agent process). go switches the unit on only when every case matches, gate passes and bench shows it is not slower as its callers call it; a slower stage names the batch class to call from the loop or the caller to port with it. Report its stage and next step to the user. rust-anything report <crate> then writes report/REPORT.md and report/card.svg with measured numbers for the pull request.
0. Profile: find what is worth moving
When the goal is speed, measure before choosing anything:
rust-anything profile <repo> -- node bench.mjs # or: python3 bench.py, ruby bench.rb,
# java -cp out Main, go test -run X -bench . ./pkgIt runs a real workload under the runtime's own profiler and lists hot functions with their callers and advice. Go profiles only through go test; C is not supported (use perf).
- A small function called once per item is not worth porting alone: one call into Rust costs
more than its work, and JITs (V8, the JVM, Go) run it in nanoseconds. Port it together with its callers, or batch it (step 2b). The advice line says which, with the exact command.
- Code that is already compiled (numba
@njit, Cython,@jax.jit) runs as machine code: a Rust
port gains little speed. profile lists it under "Already compiled" and says so in the advice of every hot function that calls it; tell the user before porting it for speed.
- If the user only wants a migration, skip to step 1.
1. Plan, then stop
rust-anything analyze <repo> -o plan.md # people rust-anything analyze <repo> --json # you: schema rust-anything/analyze@1
- Present the
start_hereunits (best first ports) and the order by package and wave. - Call out
keepunits (UI, editor code: they stay in the source language),blockedunits and
their reason, and dependencies with fit none or unknown. Do not hand-roll a missing crate silently: flag it.
- Wait for the user's approval of the plan and of the first unit.
2. Port one unit
rust-anything bridge <repo> <unit-id> # crate in <repo>/rust/<name>; never overwrites rust-anything record <crate> # the original's behavior on edge-case inputs -> cases.jsonl
- If the original has tests, record their calls too:
record <crate> --from-tests -- npx jest
(TS/JS, any runner) or -- pytest (Python). Every call the suite makes to the unit's exported functions becomes a case; the source is restored afterwards. Exports that are not function declarations (export const f = () => ...) are listed as not captured.
- Add real-world inputs with
--inputs cases.jsonl({"fn": name, "args": [...]}per line) when
the generated ones cannot reach the interesting paths (structured arguments, domain strings).
- TS that cannot run directly in Node (extensionless imports, path aliases): record from built
output with --module dist/x.mjs, or pass --node-arg=--import=tsx.
- If the original has no tests,
recordis the characterization suite: keepcases.jsonl.
Write the port in src/port.rs only; src/lib.rs and the wrappers are generated. After changing a signature in port.rs, run rust-anything refresh <crate>.
- Read each risk the plan lists for the unit, at its
file:line, before writing code. - String offsets: JS and Java index UTF-16 code units, Rust UTF-8 bytes: use
src/utf16.rs. - Errors: return
Err("TypeName: message"); it becomes that exception in Python, Ruby and Java,
and the error text in Go. In Python a built-in exception goes by its name; the original's own class by its dotted path, Err("mypkg.errors.ParseError: message"), which the bindings import. Inside port.rs, a small error enum is clearer; turn it into that string only in the exported function.
- Letters and digits: Rust's
char::is_alphanumerictakes more than Java's
Character.isLetterOrDigit (letters and decimal digits, per UTF-16 unit, so nothing beyond U+FFFF) or Python's str.isalpha (letters only). Match the original's rule by general category.
- Numbers in Python and Ruby: ints that the original passes through must come back as ints;
in Python ports use crate::pynum::Num for int-or-float, not serde_json::Value.
- C: inputs recorded as
crash:are undefined behavior; any result passes. - C pointers: a byte pointer with a length parameter is
&[u8](or&mut [u8]when the
function writes it), a pointer to one scalar is Option<&mut T>, and a returned pointer into a parameter is its offset (Option<usize>). In --inputs, give buffers as hex text (a number means that many zero bytes, null is NULL) and leave length parameters out; recorded results then hold the return value and what the function wrote. A struct of scalar fields passed or returned by value is a #[repr(C)] struct at the crate root (crate::AVRational), and an object of its fields in cases. A char ** / const char ** the function points into the first char string argument is Option<&mut Option<usize>> (the offset into it); in cases give the starting offset, true for a NULL start, or null for a NULL **. Contexts, other structs and other ** stay blocked: bridge a small wrapper with plain arguments, and say so. Pass the project's build flags in CFLAGS (-DHAVE_CONFIG_H, -I<root>) when its sources need them.
- C strings:
const char *isOption<&[u8]>, which costs astrlenper argument. Where that
dominates (short-string helpers), type the parameter Option<crate::CChars<'_>> in port.rs and run refresh: the port reads the bytes as it goes (next, peek, to_bytes).
- Ordered maps and object keys:
indexmapwhere order reaches output. - Regex lookaround or backreferences:
fancy-regex, notregex. Either way,\w,\b,\d
and case-insensitive matching treat non-ASCII text differently from the source language's engine: passing the recorded cases is not enough. record adds regex traps (Turkish i, Kelvin sign, joiners, non-ASCII digits and spaces) to functions in files that use regexes; ask the user for real text the patterns see, record it with --inputs, and set unicode(false) or spell out ASCII classes ([A-Za-z0-9_]) where the original's \w is ASCII-only (JS without u, Java).
- No
unsafe. If truly needed: minimal, isolated, with a// SAFETY:comment. - Add Rust unit tests in
port.rsfor the cases you reason about.cargo testpassing with no
tests proves nothing: the recorded cases are the proof.
- To silence a lint, use
#[expect(lint, reason = "...")], not#[allow], so it is flagged once
it no longer applies.
2b. Batch a hot loop
For a function called over many items (search, scoring, formatting a list):
rust-anything bridge <repo> <unit> --batch fn:param # or: rust-anything refresh <crate> --batch fn:param
This generates a class that takes the param values once and keeps them in Rust: new FnBatch(items) (TS, Python, Java), Mod::FnBatch.new(items) (Ruby), NewFnBatch(items) (Go). Per query, run(<other args>) returns every result as one array, and rank(<other args>, min) returns the item indexes, best first. It runs on all cores, and errors are the original's. Close the batch when done in Go and Java (finalizers are only a fallback).
- Make the caller build the batch once, not per query. Map returned indexes back to items with a
plain loop; in JS, Array.from(order, fn) costs 20x more.
- To prepare items once (lowercase, masks, position tables), define
pub struct FnIndexin
port.rs with new(items) and run(<other args>) -> Result<Vec<R>, String>. It must give the same result as the function, item by item: test it against the function over every item.
- When ranking can skip work, give the index its own `rank(<other args>, min) -> Result<Vec<u32>,
String>` (narrowing to the last query's matches as the user types, table lookups). It must match ranking the function's results: score high to low, ties in item order.
- A batch multiplies the port's per-item speed by the cores. Against compiled originals (Go,
Java) the port itself must be fast: handle ASCII without Unicode tables, build each result in one pre-sized String, avoid intermediate copies. Keep diff passing.
- Items and other arguments: numbers, booleans and strings (Ruby: any value); results: numbers,
booleans or strings. Not for C.
- Batch crates allocate with mimalloc, which is built from C. Pass
--allocator rusty_allocto
bridge if the target has no C compiler.
3. Prove it
Preview shortened. The full SKILL.md is in the pack.
| File | Size | SHA-256 |
|---|---|---|
| SKILL.md | 15.8 kB | f752bd6a9068 |
| SKILVAULT_SOURCE.json | 1.3 kB | 419b3643d118 |
| THIRD_PARTY_NOTICES.md | 1.1 kB | 15cb3de2fed7 |
| whole-app.md | 15.6 kB | 6228c0d7f46d |
Published verbatim from the pinned commit. Nothing is rewritten.
| Version | Pinned commit | Signed | |
|---|---|---|---|
| 0.1.0 Current | 6960944448dd | 23 Nov 2026 |
Locking a skill to one version needs Pro.