rust-anything
将你的整个应用重写为 Rust,全程保持可用。
CLI、服务器与库,逐块迁移,每一步都与原版校验。
最高提速 20 倍 · 重放 38,251 个录制用例 · 0 不匹配 · 一条命令
将你的整个应用逐步重写为 Rust。 rust-anything 会录制你的 TypeScript/JavaScript、Python、C、Go、Ruby 或 Java 应用当前的行为,然后在迁移的每一步都将 Rust 重写结果与该录制内容进行校验,直到整个应用变为纯 Rust。支持 CLI、HTTP 服务器与库;由你的编码代理(或你自己)编写 Rust。它只能捕获录制所覆盖的内容:见它无法捕获什么。如果只需要让慢的部分变快?只迁移那部分,一次迁移一条热点路径:
| 真实工作负载,结果与原版一致 | 原版 | 使用 rust-anything |
|---|---|---|
| x18n 的侧边栏搜索,50,000 个键(TypeScript、Node) | 每次查询 10 ms | 0.5 ms:快 20 倍 |
| 浏览器中的同一搜索(wasm,单线程) | 10 ms | 0.95 ms:11.5 倍 |
对 20,000 个字符串执行 slugify(Python) | 98 ms | 快 17 倍 |
Ruby 标准库的 Shellwords.shellescape,50,000 个值 | 88 ms | 快 11.8 倍 |
对 50,000 个字符串执行 Slugify(Go) | 49 ms | 快 4 倍 |
对 50,000 个字符串执行 slugify(Java) | 43 ms | 快 3 倍 |

在 4 核上测得;每个数字都在 demo/ 中有对应基准测试,且会先校验结果完全一致。对每个小函数调用一次 Rust 通常比 JIT 更慢;rust-anything 会找到值得迁移的循环并迁移它。
rust-anything 是一个独立项目,与 Rust Project 或 Rust Foundation 无任何隶属关系,也未获其认可。“Rust” 是 Rust Foundation 的商标。
快速开始
将以下内容粘贴到 Claude Code、Codex、Cursor 或 Gemini CLI 中,让你的代理安装:
Install rust-anything: run `cargo install rust-anything`, then `rust-anything setup`.
Tell me when to restart you.
或自行操作:
cargo install rust-anything # from crates.io
rust-anything setup # registers it with Claude Code, Codex, Cursor and Gemini CLI
还没有 Rust 工具链?macOS、Linux 和 Windows 的预编译二进制文件附在每个 GitHub release 中;对于 JavaScript 项目,npm install -g rust-anything 会安装同一二进制。
在 Claude Code 中也可以将其作为插件安装(MCP 服务器与技能;上述 CLI 需在你的 PATH 中):
/plugin install rust-anything --marketplace erkamyaman/rust-anything
setup 会为它找到的每个代理添加 MCP 服务器,并在代理读取技能的位置安装工作流技能。它会保留你的其他设置,可安全重复运行,--remove 可撤销。然后向你的代理提问,例如:
- “用 rust-anything 把这个 CLI 端到端重写为 Rust,并证明行为一致。”
- “这个搜索很慢。用 rust-anything 做性能分析,把热点循环迁移到 Rust。”
- “用 rust-anything 规划
src/parser/的迁移方案;先迁移第一个单元并验证。” - “将
rust/text-rs中的 Rust 移植版与原版做基准对比,告诉我是否该上线。”
支持的代理
| 代理 | rust-anything setup 添加的内容 |
|---|---|
| Claude Code | ~/.claude.json 中的 MCP 服务器,~/.claude/skills/ 中的技能 |
| Codex | ~/.codex/config.toml 中的 MCP 服务器,~/.codex/skills/ 中的技能 |
| Cursor | ~/.cursor/mcp.json 中的 MCP 服务器 |
| Gemini CLI | ~/.gemini/settings.json 中的 MCP 服务器 |
| 其他任意 MCP 客户端 | 手动将 rust-anything mcp 添加为 stdio 服务器(见安装) |
在修改已存在的文件前,setup 会在其旁边保存一份副本(<file>.rust-anything.bak)。
或自行运行各步骤:

rust-anything profile . -- node bench.mjs # 热点在哪,谁在调用
rust-anything bridge . src/fuzzy.ts --batch fuzzyScore:text
# 编写 src/port.rs(或让你的代理编写),然后:
rust-anything record rust/fuzzy-rs && rust-anything build rust/fuzzy-rs
rust-anything diff rust/fuzzy-rs # 每个录制用例都必须匹配
rust-anything bench rust/fuzzy-rs # 更快了吗?结论会说明
rust-anything gate rust/fuzzy-rs # done 表示通过
rust-anything 不翻译代码:你的编码代理(Claude Code、Codex、Cursor……)或你自己编写 Rust。rust-anything 提供代理无法可靠猜出的内容:时间花在哪里、先迁移什么、按什么顺序迁移、一个让其余代码以原 API 不变方式调用 Rust 的桥接、移植必须匹配的精确行为、一个安全的上线方式,以及一个判断移植何时完成的关卡。
语言
| 语言 | 单元 | 桥接 | 录制与重放由 |
|---|---|---|---|
| TypeScript/JavaScript | 文件夹或文件 | napi-rs 或 wasm-bindgen,配生成的二进制 wire;含类与 async | Node,运行 .ts 源码 |
| Python | 包或模块 | PyO3(abi3)、直接转换、类型化异常 | Python,导入原模块 |
| C | .c 文件 | 带原名与头文件的 extern "C" 函数 | 原程序编译为共享库,经 ctypes 调用,每个用例一个 fork |
| Go | 包 | 类型化 cgo 调用与生成的二进制 wire,置于保留原 API 的包中 | 生成的 Go 驱动,构建为独立模块 |
| Ruby | 文件或模块函数文件夹 | 置于原模块下的 magnus 扩展 | 生成的 Ruby 驱动 |
| Java | public static 方法包 | 类型化 JNI 与生成的二进制 wire,置于含原方法的包装类中 | 生成的反射驱动 |
| PHP(预览) | 函数与 public static 方法文件夹 | 下一步:C ABI 之上的 PHP FFI | 目前支持整个应用:app record、app replay 与前置入口,用于 CLI 与服务器(php -S) |
| C#(预览) | public static 方法文件夹 | 下一步:C ABI 之上的 P/Invoke | 目前支持整个应用:app record、app replay 与前置入口,用于 CLI 与 ASP.NET 服务器(dotnet <app>.dll) |
除 C 外每种语言还支持批量类(--batch):元素只穿越一次并留在 Rust 中,每次调用在所有核心上对全部元素执行。
语言根据仓库自动检测(go.mod、pom.xml、.csproj 或 .sln、pyproject.toml、Gemfile、composer.json、package.json,否则为最常见的源文件);--lang 可覆盖。类型来自源码:TS 类型、Python 类型提示、C、Go、Java 与 C# 签名、Ruby YARD 标签、PHP 类型与 phpdoc;被用作数字的未类型化参数会被推断为数字。
PHP 处于预览阶段:analyze 规划 PHP 应用(Composer 包与 PSR-4 自动加载、宽松比较与整数溢出为浮点等风险、Composer 包到 crate 的映射),且 PHP CLI 或服务器可被录制、重放并置于 Rust 前置入口之后。通过 PHP FFI 将其单元移植到 Rust 是下一步(issue #2)。
C# 同样处于预览阶段:analyze 读取 .csproj 项目及其 NuGet 包(映射到 crate),将 using 指令解析到文件夹,并标记 C# 的差异点(decimal、dynamic、LINQ 延迟查询、Task、lock、反射)。C# CLI 或 ASP.NET 服务器可被录制、重放并置于 Rust 前置入口之后;通过 P/Invoke 移植单元是下一步。
工作原理
profile ──> analyze ──> bridge ──> record ──> port.rs ──> diff ──> bench ──> shadow ──> gate
where the what to the Rust what the you or every faster? both side done means
time goes port first crate and original your agent recorded the by side in this passes
wrapper does write it case verdict production
原程序始终是唯一事实来源:record 在边界用例(及你自己的输入)上运行它并保存其返回或抛出的内容;diff 将每个用例对 Rust 进行重放;在全部匹配且 gate 通过之前不会上线。整个过程中调用方始终使用原 API。
整个应用在同一循环中逐单元迁移,置于一个证明 w
hole program (Port a whole app):
analyze --whole-app ──> app record ──> app front-door ──> per unit: the loop above, then app wire ──> app lift
shape, every what the app Rust owns the gate passes, so the unit answers in pure Rust,
dependency, the does from the entry point; the Rust: replay 100%, fallback rate down proved by
decisions to make outside original answers replay
The loop
| Step | Command | What it does |
|---|---|---|
| 0. Profile | rust-anything profile <repo> -- node bench.mjs | Runs a real workload under the language’s profiler (node, cProfile, go test pprof, JFR, a Ruby tracer): hot functions by inclusive time, their callers, and which loops to batch; flags code that is already compiled (numba, Cython, JAX), where Rust gains little |
| 1. Plan | rust-anything analyze <repo> | Units, port order, risks with file:line, bridge per unit, dependency-to-crate fit, best first ports; --whole-app adds entry points and shape, every dependency (imported or declared) with its crate, pieces (units that import each other move together) and numbered decisions with a recommended answer |
| 2. Bridge | rust-anything bridge <repo> <unit> | Crate with the bindings (lib.rs, plus the wrapper the source language loads) and stubs to port (port.rs); --batch fn:param adds a class that keeps many param values in Rust |
| 3. Record | rust-anything record <crate> | Runs the original on generated edge cases (non-ASCII, emoji, -0, NaN, ints where floats are expected, …) and on every semantic trap in every parameter (string length and case, signed division, overflow edges, float printing, map and sort order), and saves cases.jsonl; --float-tolerance 1e-9 lets floats match within that share for numeric code |
| 3. Build | rust-anything build <crate> | Builds the Rust side: .node, wasm package, Python extension or shared library |
| 3. Diff | rust-anything diff <crate> | Replays the recorded cases against Rust, called the way the original’s callers call it; lists mismatches |
| 3. Bench | rust-anything bench <crate> | Times the recorded cases on the original and on Rust, bridge included |
| 4. Shadow | rust-anything shadow <crate> | Drop-in that runs both, returns the original’s result, reports mismatches; RUST_ANYTHING_MODE=old|shadow|new |
| 5. Gate | rust-anything gate <crate> | fmt, clippy -D warnings, tests, unsafe audit, nothing unported, a recorded failing case for every error path of the original, no unwrap/expect/panic! where the original returns an error (unless marked // INFALLIBLE: <why>), build, API, behavior |
| Agents | rust-anything setup | Registers the MCP server (rust-anything mcp, every step as a tool) and the workflow skill (skills/rust-anything/SKILL.md) with your coding agents |
Port a whole app
The goal is a pure Rust app that behaves like the original, with the original kept as reference. Your agent writes the Rust; rust-anything orders the work, scaffolds it, and proves every step. The whole-app skill walks the agent through it, starting with the decisions only you can make:
- Grilling: the agent asks in rounds, each question with its recommended answer, until every
decision the port depends on is settled, and writes each one as an ADR in
rust/DECISIONS.md, withrust/GLOSSARY.mdmapping the original’s terms to Rust names. - Research: background agents read each dependency’s primary sources and write
rust/research/<topic>.md, with every semantic trap they found. - Across sessions:
rust/MAP.mdlists every unit with its state; a session claims one unit before it starts, and each checkpoint leaves arust/HANDOFF.mdfor the next session. Units in one wave can be ported in parallel by subagents. - Cutover: the agent does what it can and writes
rust/cutover.sh, an interactive script for the steps only you can do (deploys, DNS, secrets), with a way back at each step.
Grilling, research and these practices are adapted from Matt Pocock’s skills.
Plan first: rust-anything analyze . --whole-app adds the app’s shape (CLI, server or library)
and entry points, every external dependency (imported or declared) with its Rust crate and fit,
the port order as pieces (units that import each other move together), and numbered decisions
with a recommended answer: keep units, blocked units, dependencies with no or a partial crate.
Then prove the whole program from the outside. record and diff prove one unit; app record
and app replay prove the app, for CLIs and servers in any of the six languages (the app is a
black box):
rust-anything app record . -- python3 cli.py # the command that runs the original
rust-anything app replay . # the original must pass 100%
rust-anything app replay . --build "target/release/mytool"
app recordruns the original on the app’s own documented examples ($ mytool ...lines in its Markdown and shell files, with the files they name), an--inputsJSONL file ({"name", "args", "stdin", "env", "files"}), and semantic traps derived from those cases (non-ASCII and emoji strings, negative division and modulo, overflow, large and tiny floats, map order, missing files). Each case runs twice; what differs between the two runs becomes a[..]wildcard.--normalize timestamps|uuids|key-orderor--normalize name=regexadds normalizers, saved with the cases.- Cases are trycmd files in
rust/app-cases/:<case>.toml(argv, env, exit code),.stdin,.stdout,.stderr,.in/(files in) and.out/(files written). Read and edit them by hand; a Rust test can run them withtrycmdonce the port has a binary. app replayruns any build against the cases, printspassed/total, writesrust/app-cases/replay-report.mdwith a diff per failing case, and exits non-zero on any mismatch. A build that appends to the file named byRUST_ANYTHING_FALLBACK_LOG(one line per fallback to the original), as the front door below does, also gets its fallback rate reported.app replay --case <name>reruns one case by the name the report gives it: the fast, repeatable loop for fixing a mismatch before running everything again.
Then move the entry point to Rust and hand it commands one unit at a time:
rust-anything app front-door . # rust/app: every command runs the original
rust-anything app wire . textkit --command upper # after textkit-rs passes gate
# write the glue in rust/app/src/units/textkit.rs, then:
rust-anything app wire . textkit # 100% again, lower fallback rate
app front-doorscaffoldsrust/app, a Rust binary named after the app: a clap parser for the commands and flags in the recorded cases, where every command runs the original with the same argv, stdin and environment and passes its output and exit code through. Each fallback is counted, so replaying the fresh front door gives 100% passed at 100% fallback (it builds and replays to show it). It never overwritesrust/app: the code is yours from then on.app wire <repo> <unit> --command <name>runsgateon the unit crate (--skip-gateif it just passed), adds it torust/appas a library, writessrc/units/<unit>.rsonce for you or your agent to fill in (parse the arguments, call<crate>::port, print what the original prints), routes the commands to it, then builds and replays.RUST_ANYTHING_UNIT_<NAME>=originalsends a wired unit back to the original until the lift.
Wire the app’s own name as a command (--command mytool) for argv that names no command: no
arguments, unknown commands, usage errors.
When replay passes with fallback rate 0 and every unit passes gate, make it a pure Rust app:
rust-anything app lift .
app liftrefuses until both hold, and says what blocks it: the cases still falling back, glue still a stub, units failing gate.- On a copy first, it removes the fallback path and the kill switches, turns each unit crate into
a plain library of
rust/app(nocdylib, bindings or generated wrappers), and addsrust/app/tests/app_cases.rs, which runsrust/app-caseswith trycmd oncargo test, so CI needs nothing but cargo. - Then it runs the lift checklist: fmt, clippy
-D warningsand tests on every unit and onrust/app, every target named inrust/DECISIONS.mdbuilt or checked where it is installed, files read at run time and asset folders not embedded, and replay on the pure binary. Only when all of it passes are the changes written back. The original is never touched.
Servers
The same commands prove HTTP servers. --http says the command starts a server; it takes its
port from PORT or {port} in the command (--port for one that always listens on the same
port):
rust-anything app record . --http -- node server.js
rust-anything app replay .
rust-anything app front-door . # axum: every route proxied
rust-anything app wire . api --route 'GET /users/{id}' --route '*'
rust-anything app lift .
- Requests come from
curllines in the app’s docs (curl -X POST -d ... http://localhost:8080/x),--inputs({"name", "method", "path", "headers", "body"}) and traps: path segments and query values swapped for the same traps as CLI arguments, bodies for text and JSON traps, and an unknown route. Each run starts the server fresh and sends the requests in name order, so state between requests is kept. - Cases are
rust/app-cases/http/<case>.toml(the request, the status and the headers that matter) and<case>.body(the response body, with[..]where two runs differed). Date, server and other per-response headers are left out; delete any header line you do not care about. - The front door is an axum server that starts the original on a port of its own and proxies
every route no unit answers.
wire --routetakes axum routes:METHOD /path/{param},/pathfor any method,*for everything else; the glue gets the route, its parameters and the request.liftremoves the proxy; HTTP cases then run in CI withapp replay.
Libraries
A library has no process to replay: its public API is the front door, and each unit’s recorded cases are the proof.
rust-anything app front-door . # rust/app: a Rust crate with the public API
# each unit through the loop: bridge, record, port.rs, build, diff, gate; then:
rust-anything app wire . textkit-rs # re-exported from rust/app; the original imports its shadow
rust-anything app replay . # every wired unit's cases; fallback = exports still in the original
rust-anything app lift .
app front-doorfinds the public API (every unit’s exports) when the repository has nomainand no server (--libraryotherwise), and scaffoldsrust/appas a library crate. Each wired unit becomes a module of it:pub use textkit_rs::port as textkit;.app wiretakes a crate made bybridge, runsgate, and writes the unit’s shadow drop-in: the original package imports it in place of the unit, so its callers keep the original API and reach the Rust.RUST_ANYTHING_UNIT_<NAME>=originalsends the unit back (C: build without the shadow’s flags).app replayruns every wired unit’s recorded cases through its bindings. The fallback rate is the share of public exports Rust does not answer yet: unwired units, and exportsbridgekeeps in the original language.app liftneeds fallback 0 and every unit throughgate; it strips the bindings, wrappers and shadows from the units and leavesrust/appas one pure Rust library. It does not touch anyport.rs, so the cases that matched through the bindings still describe it; the checklist warns about files of the original that still import the shadows.
All five are MCP tools too: app_record, app_replay, app_front_door, app_wire and
app_lift.
Case study: x18n’s core
All 29 functions of x18n’s core that can move without an API change were ported with rust-anything:
every gate passes and 7,925 recorded cases match exactly. rust-anything bench then showed the ports
are slower than the TS as called from JS, because the bridge costs more than the work. Full report:
demo/x18n-core. The lesson is built in: measure with bench before
shipping a port.
Hot paths: keep the data in Rust
A port called once per item pays the bridge once per item, and loses to a JIT. What wins is
moving the loop: profile finds it, and --batch generates a class that takes the items once
and runs the function over all of them per call, on all cores, with typed-array results.
rust-anything profile ../x18n -- node --experimental-strip-types $PWD/demo/x18n-search/search.ts .
# -> fuzzyScore: a quarter of the run, called per key by `matched`: batch it
rust-anything bridge ../x18n packages/core/src/fuzzy.ts --batch fuzzyScore:text
const search = new FuzzyScoreBatch(keys) // once
const order = search.rank(query, 0) // per keystroke: indexes, best first
A FuzzyScoreIndex struct in port.rs replaces the default loop with one that prepares the
items once, and can rank by itself (rank): it keeps the keys lowercased with a character mask
each, a table of each key’s first position of every common character (a one-letter query is one
column), and the last query’s matches (typing se after s rescores only what s matched). On
x18n’s sidebar search over 50,000 keys, typed letter by letter, with identical results:
| Per query | vs TS | |
|---|---|---|
TS: map(fuzzyScore), filter, sort | 10 ms | 1x |
| TS with the same narrowing as the index | 4.1-5.4 ms | 2x |
| The same port, called per key | - | 0.2-0.4x |
FuzzyScoreBatch, default index (4 cores) | 5.1 ms | 1.7x |
FuzzyScoreBatch with FuzzyScoreIndex (napi, 4 cores) | 0.45-0.56 ms | 18-22x |
| The same with wasm (one thread) | 0.95 ms | 11.5x |
Against TS doing the same narrowing, Rust is still 7-12x faster (wasm 5x). Turn the returned
indexes into keys with a plain loop: Array.from(order, i => keys[i]) cost 20x more, 0.4 ms.
Every language gets batches, and they beat the original even where per-call ports lose. The same work on 4 cores, identical results and errors (benchmarks in each demo folder):
| Language | Workload | Original | Per-call port vs original | Batch vs original |
|---|---|---|---|---|
| TS | x18n search, 50,000 keys | 10 ms | 0.2-0.4x | 20x |
| Python | slugify, 20,000 strings | 98 ms | - | 17x |
| Ruby | slugify, 20,000 strings | 110 ms | - | 12.7x |
| Ruby | shellescape (stdlib), 50,000 mixed values | 88 ms | - | 11.8x |
| Go | Slugify, 50,000 strings | 49 ms | 0.93x | 4x |
| Java | slugify, 50,000 strings | 43 ms | 0.68x | 3x |
Compiled originals gain less: the per-item work is already fast, so the batch wins by the number of
cores. Batch crates allocate with mimalloc: with the system allocator the Go batch was slower than
one thread. Demo: demo/x18n-search.
Real code in six languages
Go’s path, Ruby’s shellwords, Python’s colorsys, JDK and glibc behavior behind small
facades: every port passes its gate, 13,010 recorded cases in all. The runs found and fixed
bugs in rust-anything (floats off by one ULP through serde_json, C crashes during recording,
untyped code getting garbage inputs). Called per function, the Ruby port runs 4.4x faster than
Ruby and the Python port 1.35x faster than CPython, while Go and Java leaf functions stay faster
in their own language; as batches, all of them win (see the table above).
Report: docs/real-world-languages.md.
Example: a real module from x18n
packages/core/src/fuzzy.ts from x18n, ported both ways in
demo/:
rust-anything analyze ../x18n # fuzzy.ts: ready, wasm-bindgen (core runs in browsers)
rust-anything bridge ../x18n packages/core/src/fuzzy.ts --out demo/fuzzy-rs
rust-anything record demo/fuzzy-rs --count 2000
# write src/port.rs
rust-anything gate demo/fuzzy-rs
A first port that indexed by Rust char passed simple tests but failed diff:
198/200 cases match
- fuzzyScore("b😀", "a😀b😀c"): expected {"ok":1997}, got {"ok":1998}
JS indexOf counts UTF-16 code units, so an emoji is two positions. The port in
demo/*/src/port.rs uses the generated utf16 helpers and passes 2000/2000 cases and the gate,
as napi-rs (demo/fuzzy-napi) and as wasm-bindgen (demo/fuzzy-rs).
The plan rust-anything writes for all of x18n: docs/examples/x18n.md.
Install
cargo install --path .
record, diff and bench run the original in its own runtime: Node 22.6+ for TS (it runs .ts
sources directly), Python 3.9+ for Python and C (ctypes), Go 1.21+, Ruby 3+, JDK 17+
(javac and java). C also needs a C compiler. wasm bridges also need rustup target add wasm32-unknown-unknown and
cargo install wasm-bindgen-cli --version <the crate's wasm-bindgen version> --locked; build names
the exact version.
For agents, rust-anything setup registers everything (see Quick start). To add the MCP server to
one project by hand instead (.mcp.json):
{ "mcpServers": { "rust-anything": { "command": "rust-anything", "args": ["mcp"] } } }
What bridge decides
- Exports that cannot cross a bridge stay in the source language, with the reason, and the shadow
module re-exports the original. For TS:
functions that take or return functions, generators and iterators, RegExp,
instanceofchecks, generics, and values whose types (followed through imports, re-exports andextends) hold functions.--keep "name: reason"keeps more, e.g. code that depends onIntldata. - TS types map to Rust types, with type aliases resolved through imports and parameter types inferred from default values; structured values cross as a generated binary wire (JSON only as a fallback for shapes the wire does not model).
- JSON cannot express
undefined, NaN, Infinity, -0 or lone surrogates: structured values carry markers ({"$undefined": true},{"$num": "NaN"},{"$utf16": [...]}) that the generatedindex.cjstranslates, with helpers in the crate’sjs.rs.
record runs TS sources as they are: a Node resolve hook follows bundler-style imports
(./errors to ./errors.ts), --resolve-from supplies npm packages when the repo has none
installed, and TS that needs transforming (enums, parameter properties) is retried with
--experimental-transform-types.
What analyze looks at
- Packages (
package.json) and source files; skipsnode_modules, build output, fixtures, playgrounds, tool configs. Vue/Svelte/Astro<script>blocks are parsed for imports. - Units: a folder of source files, or a file at a package’s source root.
- Waves: a unit’s imports come in earlier waves; import cycles are ported together.
- Bridge: napi-rs when the unit or anything it imports needs Node; wasm-bindgen for portable code; keep in JS for UI and editor code.
- Readiness (how safe) and priority (safe and worth it: loops and string work, tests, size).
| Risk | Severity | Example |
|---|---|---|
| String offsets | high | slice, indexOf, matchAll, the d flag: UTF-16 vs UTF-8 |
| Regex syntax | high | lookaround, backreferences, y: not in the regex crate |
| Dynamic regex | high | new RegExp(userPattern): JS syntax at runtime |
| Dynamic code | high | eval, new Function, computed import() |
| Dynamic typing | medium | any, 'key' in value |
| Ordered collections | medium | Map, Set, Object.keys: insertion order |
| Async, generators | medium | promise and generator boundaries |
| Class inheritance, reflection | medium | extends, Proxy, Reflect, Symbol |
| Callback-shaped APIs | medium | function-typed params and methods: chatty bridges |
| Exceptions, numbers, JSON | low | throw, bitwise ops, JSON.stringify order |
Development
cargo test # unit tests, fixture repo, record/diff/shadow loop (needs node), app record/replay per language
cargo clippy --all-targets -- -D warnings
cargo fmt
Design choices and their reasons: DECISIONS.md.
Update or remove
cargo install rust-anything # update (Cargo)
npm install -g rust-anything@latest # update (npm)
rust-anything setup # refresh agent settings
rust-anything setup --remove && cargo uninstall rust-anything # remove (Cargo)
rust-anything setup --remove && npm uninstall -g rust-anything # remove (npm)
setup --remove takes out only rust-anything’s entries; the copies it saved
(<file>.rust-anything.bak) stay until you delete them.
What it can’t catch
Passing means the Rust matches every case that was recorded, nothing more. What bites rewrites usually lives outside the recording, so know where the edges are:
- Inputs nobody recorded. The generated cases, the traps and your own
--inputsare the ceiling. Add real inputs (production samples, bug reports, the original’s test fixtures); the user input that breaks prod is rarely one a generator thinks of. - Regexes. The
regexcrate has no lookaround or backreferences, and even a pattern that compiles can treat\w,\b,\dand case-insensitive matching on non-ASCII text differently from JS, Python or Java. Swapping infancy-regexor rewriting the pattern can pass every recorded case and still differ on a Turkish dotlessıor a zero-width joiner.recordadds regex traps (those, the Kelvin sign, long s, Arabic-Indic digits, line separators, final sigma) to every function in a file that uses regexes, but fuzz your real patterns against real text too. - What changes between runs.
recordruns the original twice and sorts out what differed: changed values (times, ids) become wildcards; the same lines in another order (hash maps, concurrency) are compared in any order, so a port still has to produce exactly those lines; a different number of lines becomes..., which matches anything.recordlists each kind: look at every one, since a hash-order or concurrency difference is exactly what can change for real in a port. - Floats. Number-to-text formatting differs between languages (
1e21,-0, digit counts). The traps include those values, and they must match exactly;--float-toleranceforgives rounding only, never formatting. - Anything not in the output. Timing, memory, concurrency under load, and side effects other than stdout, stderr, exit codes, written files and HTTP responses (network calls, databases, signals) are not compared.
- Other platforms. A recording proves behavior on the machine that ran it. C whose results
depend on type sizes, endianness or the compiler can behave differently on the target;
analyzekeeps hardware-facing C in C for that reason.
FAQ
Does it rewrite my code automatically? No. It finds what to move, generates the bridge,
records what the original does and checks the Rust against it. You or your agent write the Rust
in port.rs; diff and gate decide when it is right.
Will my app’s API change? No. Callers import the same functions (or the shadow module, which runs both and returns the original’s result while you build confidence).
Is Rust always faster? No, and rust-anything says so. A small function called once per item
is often slower in Rust, because each call crosses a bridge; V8, the JVM and Go run such functions
in nanoseconds. profile finds the loop around it, --batch moves the whole loop, and bench
gives a verdict before you ship. Code already compiled by numba, Cython or JAX runs as machine
code too: profile and analyze flag it, since porting it buys little speed.
My code is numeric; will the floats match exactly? Often not: operation order, fused
multiply-add and the math library differ between compilers. Record with --float-tolerance 1e-9
(record or app record), and floats match within that share of the larger value (absolute below
1). Integers, text and structure still have to match exactly.
Can it port an app I only have as an APK, a JAR or an .exe? No. It ports source code: it
parses the functions, records what each one does, and checks the Rust against the running
original. A compiled app has none of that to work with, and analyze says so. Writing a new Rust
app from a binary’s visible behavior is a different project.
Should I port battle-tested C? Often not, and analyze tells you where. C that touches
hardware registers, relies on its compiler’s type sizes or memory layout, or uses inline assembly
(volatile, bitfields, packed structs, __asm__, integers cast to addresses) is marked “keep in
C”: a recording on your machine proves nothing about the target, and stable driver or firmware
code gains little from a rewrite. The portable logic around it (parsing, protocols, data handling)
is what moves well.
Can it port my Electron app? The logic, yes; the windows stay web pages. analyze --whole-app spots Electron and plans the main process piece by piece while the renderer stays as
it is. Moving the UI to Tauri (the same web UI on a Rust backend) is a separate step once the logic
is Rust.
What about C#, Kotlin or Swift? C# is in preview (see Languages); Kotlin and Swift are not supported yet. Each language needs a parser, a recorder, a bridge and a replay driver, all tested end to end. Open an issue (or upvote one) for the language you need.
Won’t the Rust be much bigger than the original? It shouldn’t be. gate compares the port’s
lines with the original’s and fails above 3x (plus 50 lines for imports and signatures): that usually means hand-writing what a crate already
does, or handling cases one by one. analyze lists the crates to use.
Doesn’t porting piece by piece lock the Rust into the old app’s design? Only while both run
side by side. The recordings check behavior at the app’s edges (a CLI’s output, a server’s
responses, a module’s exported functions), not its internals. Mirror the old structure while
units still cross the bridge; once app lift has removed the original, restructure the Rust
freely, and app replay still proves the behavior. Nothing calls back into the original either:
the front door runs it as a separate process (or forwards HTTP to it), bridged units are called
by the original and never the other way round, and callbacks stay in the source language.
Does my code leave my machine? No: rust-anything runs locally and sends none of your code anywhere. Cargo downloads crates as usual, and your agent’s model provider sees what your agent sends it, under its own policy.
What does it need installed? Rust, plus the runtime of the language you port (see Install).
Something broke. Open an issue with the command, its output and your platform.
Contributing
Issues and pull requests are welcome. Before a pull request: cargo fmt, cargo clippy --all-targets -- -D warnings and cargo test must pass (see Development); design
choices and their reasons are in DECISIONS.md. Case studies of real ports are
especially welcome.
License
MIT © Erkam Yaman. Ports and generated code in your repository are yours.