rust-anything Won't Write a Single Line of Rust. That's the Point.
It records what your app already does, lets your coding agent port it to Rust one module at a time, and blocks every piece until it matches the recording.
- rust-anything refuses to translate code, recording what an existing program does and letting a human or coding agent write the Rust port instead.
- Every ported unit has to replay the recording and match it before it is allowed to replace anything, which turns observed behavior into a gate.
- The generator bakes in a safety boundary by splitting pure logic from FFI, so the port forbids unsafe code and stays testable without a host runtime.
- Shadow mode runs unproven Rust in production while always returning the original's result, so trust is earned before traffic is switched.
Every source-to-source translator of the last decade has answered the same question: how do we generate the Rust? C2Rust and Corrode map C syntax onto Rust syntax and hope the behavior survives the trip. A newer wave of model wrappers does the same thing with an LLM in the middle. The pitch never changes. Hand over your code, get back Rust.
rust-anything declines the premise. It does not write the port. It does not call a model. It records what your existing program actually does, hands the porting work to a coding agent or a human, and then refuses to let the ported unit replace anything until it reproduces the recording, case by case.
The Tool That Refuses to Write Your Code
The project's own decision log states the inversion outright. This is not a translator that hides a model inside. It is a toolkit your agent drives.
That single sentence reorders the whole migration. If the tool is not producing Rust, then the interesting engineering is not generation. It is measurement. Who decides whether a ported module is correct? What is the reference? How do you know the new code behaves like the old code when the old code was never specified in the first place?
The answer is a recording. The original program becomes its own specification, and the port has to earn its place against it.
Record First, Port Later
The workflow has four steps, and only one of them involves writing Rust. The tool does the other three.
- Analyze. Walk the source project, split it into units (folders or root-level files), and rank them by how ready and how valuable they are to port.
- Record. Generate deterministic inputs, run them against the original, and capture the outputs into a
cases.jsonlfile using a lossless codec. - Bridge. Generate the FFI glue for the target host: napi-rs for Node, wasm-bindgen for browsers, pyo3 for Python, a C ABI for C.
- Diff. Replay every recorded case against the Rust port. Only when all cases match does the unit move on.
The recording is the contract. A case is a compact input paired with the exact output the original produced. Floats are serialized with float_roundtrip and parsed with preserve_order for a reason stated in the manifest: recorded floats must survive parsing bit for bit. If the Rust port returns a value that differs in the last decimal place, the case fails.
{"unit":"fuzzy-score","input":{"query":"b😀","text":"a😀b😀c"},"expected":1997.0,"kind":"value"}
{"unit":"fuzzy-score","input":{"query":"","text":"anything"},"expected":0,"kind":"value"}
{"unit":"slugify","input":{"text":"Ünïcode ǝxample"},"expected":"unicode-example","kind":"value"}
How a Port Earns Its Place
The generated code enforces a boundary the compiler can check. Pure logic goes into port.rs, which opens with #![forbid(unsafe_code)]. All FFI goes into lib.rs, which is the only file a reviewer has to audit for unsafe blocks.
The reasoning is in the decision log: binding macros expand to unsafe code, the port itself never needs it, and the port stays testable without a JS runtime. Every fixture follows the pattern. In the libc reimplementation, the only unsafe blocks in lib.rs are a CStr::from_ptr and the #[unsafe(no_mangle)] exports, each carrying a // SAFETY: comment. The port file beside it is clean Rust.
Panics get the same treatment. A panic unwinding into Node aborts the process, and in shadow mode that would take the app down with it. So the napi wrapper catches panics at the boundary and converts them into ordinary errors:
fn run<T>(f: impl FnOnce() -> Result<T, String>) -> napi::Result<T> {
match std::panic::catch_unwind(std::panic::AssertUnwindSafe(f)) {
Ok(result) => result.map_err(napi::Error::from_reason),
Err(payload) => Err(napi::Error::from_reason(format!(
"Rust panic: {}", panic_message(&*payload)
))),
}
}
The AssertUnwindSafe wrapper is a deliberate narrowing, not a shrug. The closure owns its inputs and nothing shared is left half-mutated, so the override is honest. Every exported function then takes the same fallible shape, even ones that cannot fail today. The generator keeps the template uniform so a port that later gains error returns needs no change at the binding layer.
The Bugs You'd Never Catch By Eye
The most valuable thing a recording catches is the class of bug a human reviewer would sign off on. JavaScript strings are indexed in UTF-16 code units. Rust strings are indexed in UTF-8 bytes. A port that returns or consumes offsets is wrong on non-ASCII text, and it is wrong silently.
rust-anything ships a helper module for exactly this. utf16.rs mirrors the JavaScript methods a port is likely to call: units, slice, indexOf, lastIndexOf, plus converters between byte offsets and UTF-16 offsets in both directions. The module doc says the quiet part: a port that returns or consumes offsets must use these helpers, or non-ASCII text gets wrong results silently.
The fuzzy-scoring fixture shows how deep the mismatch runs. JavaScript's for...of walks code points, so astral characters stay whole, while indexOf works on code units. A faithful port has to hold both models at once. The adjacency check is the tell: JavaScript starts its cursor at -1, so the first character being adjacent means it matched index zero. The Rust version encodes that with a next == 0 branch and a comment explaining why.
// `for (const char of q)` walks code points, so astral characters stay whole.
for c in q.chars() {
// ...
}
let adjacent = previous.map_or(next == 0, |at| next == at + 1);
// The recorded case that pins all of it down:
assert_eq!(fuzzy_score("b😀".into(), "a😀b😀c".into()), 1997.0);
That assertion is not decoration. It is a recorded case that a port either matches or fails. Nobody derives 1997.0 from first principles. The original produced it, the recording kept it, and the gate enforces it.
Shadow Mode: Rust on Probation
Passing the gate on recorded cases is not the same as being trusted in production. The inputs your users send will not all look like the ones the tool generated. So the last step is the most interesting one: run both implementations live, and let the original keep the wheel.
In shadow mode, the caller always receives the original's result. Rust runs alongside, produces its own output, and any disagreement is logged as a discrepancy. Rust errors never reach a caller. A panic is caught at the boundary and reported, not thrown. The new implementation gets to prove itself against real traffic without ever being able to break it.
It is a probation period for code. Earn trust first, then earn traffic. That ordering is what makes it defensible to run half-finished Rust inside a live system, and it is the reason the panic containment in the wrapper is load-bearing rather than defensive polish.
Rewrite your whole app in Rust, one piece at a time.
What It Is, and What It Isn't
rust-anything sits between three categories of existing tooling, and it borrows from all of them without being any of them.
| Category | Examples | What they do | How rust-anything differs |
|---|---|---|---|
| Source translators | C2Rust, Corrode | Generate Rust from source code | Does not generate the port; validates a human or agent written one against recordings |
| Bridge libraries | PyO3, napi-rs, wasm-bindgen | Supply FFI between Rust and a host language | Uses these as mechanisms, then wraps them in a record, replay, and gate loop |
| Replay and diff tools | Keploy, Diffy | Record and compare service behavior | Works below the service boundary, down to individual functions and modules |
The honest limits matter as much as the pitch. The project states them, and they are worth repeating without softening.
- No equivalence for unrecorded inputs. The gate proves compatibility only for the cases that were captured. Coverage depends entirely on how good the generated inputs and the user-supplied real inputs are.
- No guaranteed speedup. Calling into Rust for each small function can be slower than a JIT. The tool itself recommends moving worthwhile loops and batches, not sprinkling FFI over everything.
- No shortcut around the porting work. Someone still has to write the Rust. The tool makes that work verifiable, not automatic.
That last point is the whole design in miniature. The hard part of a migration was never writing new code. It was knowing when the new code was allowed to replace the old. rust-anything takes the second job seriously, and leaves the first one to you.





