用 Rust 重寫你的應用程式。並證明它的行為完全相同。
rust-anything 會錄製你的程式碼做了什麼,再將每個已錄製的案例拿來重播比對 Rust 移植版本。Rust 程式碼由你的 AI 代理撰寫。在輸出完全一致之前,什麼都不會出貨。
export function wordCount(text: string): number { return text.split(/\s+/).filter(Boolean).length}
pub fn word_count(text: &str) -> usize { text.split_whitespace().count()}
Sponsored by
CodeRabbit
安裝
安裝 CLI,接著在 Claude Code、Codex、Cursor 與 Gemini CLI 中註冊 MCP 伺服器與工作流程技能。
cargo install rust-anythingrust-anything setupmacOS、Linux 與 Windows 的預先建置執行檔可在每個 GitHub release 下載。
一次移植如何完成
原始版本始終是唯一可信來源。rust-anything 不翻譯程式碼:它提供 AI 代理猜不到的資訊,以及一道判定移植何時完成的閘門。
錄製
recordrecord會以自動產生的邊界案例、語意陷阱以及你自己的輸入執行原始程式,並儲存它回傳的值或擲出的例外。移植
bridgebridge會產生 Rust crate 與包裝層,讓呼叫端繼續使用原本的 API。Rust 程式碼由你或你的 AI 代理撰寫。檢查
diff, gatediff會將每個已錄製的案例拿來重播比對 Rust 版本,在全部一致且gate通過之前,什麼都不會出貨。提升
app lift當重播在沒有回退的情況下通過,且每個單元都通過 gate,
app lift就會把它變成純 Rust 應用程式。原始版本完全不會被更動。
錄製內容抓到了什麼
x18n 的 fuzzyScore 第一版移植以 Rust char 作為索引。它通過了簡單的測試,卻沒通過 diff。
# 時間花在哪裡,以及誰呼叫了它 $ rust-anything profile . -- node bench.mjs $ rust-anything bridge . src/fuzzy.ts --batch fuzzyScore:text # 撰寫 src/port.rs(或交給你的 AI 代理),然後: $ 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
# diff,第一版移植 198/200 cases match - fuzzyScore("b😀", "a😀b😀c"): expected {"ok":1997}, got {"ok":1998} # JS 的 indexOf 以 UTF-16 程式碼單元計算, # 所以一個 emoji 佔兩個位置。 # 使用自動產生的 utf16 輔助函式後: # 2000/2000 個案例,且 gate 通過
在真實專案上實測
每個數字都有對應的基準測試,且會先確認結果完全相同。較慢的案例也一併列出:對每個小函式各呼叫一次 Rust,通常比 JIT 還慢。
經過 app lift 後,HTTP 案例在純 Rust 執行檔(5.3 MB)上全部一致,回退率 0%。六個單元通過 gate。
- 閒置記憶體,fixture 資料庫
- 74 MB → 3.5 MB
- 啟動到第一個回應
- 85 / 79 ms → 9.9 / 7.9 ms
- 完整 10,000 篇文章列表,1 個連線
- 1.2x
在 50,000 個字串上單次搜尋更快(91.2 ms → 2.8 ms,Apple M4)。3,414/3,414 個已錄製案例一致;360 次搜尋的結果與 Fuse 逐位元組相同。
- 10,000 個字串
- 27 to 30x
- 1,000 個字串
- 18x
- 50,000 個字串,單一核心
- 5.3x
案例全部一致,其中 340 個擷取自它自己的 Jest 測試。這是個好的移植,卻不是好的加速目標,而 bench 也如實指出這點。
- 單次呼叫,以已錄製案例計算
- 0.56x
- 批次,parse x100,000
- 18x
- 批次,format x100,000
- 0.8x
Orange rows are where Rust gains little or loses: the honest cases, shown on purpose.
json-server 基準測試 · 每秒請求數,第 1 次 / 第 2 次執行 · Apple M4,Node 24.15.0
| 請求(fixture 資料庫) | Node,1 個連線 | Rust,1 個連線 | Node,50 個連線 | Rust,50 個連線 |
|---|---|---|---|---|
| GET /posts | 11.1k / 10.8k | 27.3k / 23.9k | 19.7k / 20.4k | 115.0k / 110.7k |
| GET /posts/1 | 11.0k / 11.3k | 27.7k / 25.4k | 21.9k / 22.6k | 119.9k / 99.0k |
| ?_embed=comments | 8.7k / 6.6k | 22.5k / 21.8k | 13.8k / 11.0k | 98.3k / 100.6k |
| POST /comments,10 個連線 | 2,973 / 2,467 | 5,821 / 5,976 |
差距較小的情況:單一連線讀取完整 10,000 篇文章列表(1.2x),以及在大型資料庫上寫入(1.1 到 1.2x),因為兩者每次寫入都會重寫整個檔案。完整表格
語言
語言會從儲存庫自動偵測。除了 C、PHP、C# 和 PowerShell 以外,每種語言都支援批次:資料只跨越一次邊界,之後留在 Rust 中,使用所有核心處理。
已驗證TypeScript/JavaScriptjson-server、Fuse.js、vercel/ms、x18nnapi-rs 或 wasm-bindgen
已驗證Python2,400/2,400CPython colorsysPyO3
已驗證C1,859/1,859glibc 外觀層extern "C"
已驗證Go2,642/2,642Go pathcgo 與二進位線路協定
已驗證Ruby1,617/1,617shellwordsmagnus
已驗證Java4,492/4,492JDK 外觀層JNI 與二進位線路協定
已驗證PHP1,838/1,838PEAR XML_Utilext-ffi
已驗證C#2,941/2,941Google.ProtobufP/Invoke
TestedKotlinTested on a Gradle fixtureJNI through the Java bridge
TestedPowerShellTested on a .psm1 fixtureP/Invoke, pwsh 7.4+
Built by 42 contributors
Ports, parser fixes, translations and bug reports from people who use it. A good first issue is the easiest way in.

