Skip to content

Rewrite your app in Rust, piece by piece, checked against the original at every step. Works with TypeScript, JavaScript, Python, Go, Ruby, Java, C, PHP, C#, Kotlin, PowerShell and Swift.

14.8 KB
Raw Blame

rust-anything 螃蟹

Rust Anything

crates.io version npm version GitHub stars Discord MIT license
Total downloads, crates.io and npm crates.io downloads npm downloads

用 Rust 重寫你的應用程式,並證明它的行為依然完全相同。

🚀 Rust Anything 今天登上 Product Hunt。如果它幫你省下一次重寫,歡迎來打個招呼。

erkamyaman/rust-anything: #1 Rust repository of the day on Trendshift erkamyaman/rust-anything: #1 Rust repository of the week on Trendshift

文件: https://rustanything.ai/zh-tw

🌐 其他語言

要把程式碼庫遷移到 Rust?我提供 Rust 遷移諮詢: [email protected]

本譯文由社群維護,可能落後於英文 README。

贊助商

由 erKam Yaman 在 Türkiye 🇹🇷 製作
X: @RustAnything · @erkamyaman_ng
Rust Anything 免費且開源。如果它對你的工作有幫助,你的贊助能讓它持續發展。

Rust Anything 沒有任何幣或代幣。任何推銷或販售這類東西的人都與本專案無關,請不要相信任何借用這個名稱的可疑東西。

企業贊助商:CodeRabbit

Domain sponsor: Atak Domain

個人贊助商:Santosh Yadav、Hakan Soytürk、Ali Yilmaz、Ashley Hunter、Fatih Uzuntaş、bugrcvi、starwish.ing、omerrgoren

成為贊助商 Buy me a coffee

以公司身分贊助,或有其他事宜? [email protected]

要把程式碼庫遷移到 Rust?我提供 Rust 遷移諮詢: [email protected]

快速開始

把這段貼到你的程式代理中:

Install Rust Anything with npm i -g rust-anything, then run rust-anything setup. Run rust-anything go -- <slow command of this app> and finish the port until rust-anything gate passes.

或者自己安裝:

cargo install rust-anything   # 或: npm install -g rust-anything
rust-anything setup           # 把它加入 Claude Code、Codex、Cursor、Gemini CLI 和 OpenCode
rust-anything doctor          # 檢查原始程式需要的執行環境,並附上每一項的修正方法

或者用套件管理器安裝(.deb 附在每個版本發佈中;詳見安裝):

brew install erkamyaman/tap/rust-anything                              # macOS, Linux
scoop bucket add erkamyaman https://github.com/erkamyaman/scoop-bucket  # Windows
scoop install erkamyaman/rust-anything
sudo apt install ./rust-anything_*_amd64.deb                           # Debian, Ubuntu
nix run github:erkamyaman/rust-anything                                # Nix

[!WARNING] 錄製會真正執行原始程式。請在副本上操作,並讓伺服器連到測試資料庫。 record --sandbox 和 app record --sandbox 會在無網路、儲存庫唯讀、限制 CPU 和記憶體的環境中執行它(Linux 上用 bubblewrap,macOS 上用 sandbox-exec;doctor 會檢查它是否可用)。

[!TIP] **代理:**閱讀 rustanything.ai/llms.txt,了解安裝步驟、所有指令和移植流程。

運作方式

analyze 規劃要移植什麼;rust-anything go 建立橋接、錄製、讓你的代理移植並用 gate 檢查,循環直到每個錄製的案例都相符;接著 enable 把呼叫切換到 Rust

怎樣才算完成。 看行為,而不是你的測試。record 用產生的和給定的輸入執行原始程式,儲存每次呼叫的回傳值、拋出的例外和印出的輸出。gate 通過時移植才算完成:每個錄製的案例都相符,而且 fmt、clippy、cargo test、unsafe 檢查、stub 檢查,以及檢查錄製的答案是否被直接貼進移植程式碼,全部通過。你自己的測試也會執行。

你的測試變成案例。 record --from-tests -- npx jest(或 pytest)執行原始程式自帶的測試套件,並錄製它對該單元的每一次呼叫。--pin-clock 在兩邊固定時鐘和亂數,讓依賴日期的程式碼也能相符。

移植整個應用程式:analyze 做計畫,由你做決定,app record 錄製它的真實行為,前門在原始程式前面執行 Rust,單元逐個搬移,直到不再退回原始程式,最後 lift 留下一個純 Rust 應用程式

整個應用程式:CLI 和伺服器。 app record 錄製一個 CLI(結束代碼、stdout、stderr、寫入的檔案),或者加上 --http 錄製伺服器對每個請求的回應。app front-door 產生 rust/app,這是一個接管進入點的 Rust 執行檔,會把所有尚未移植的部分交給原始程式。app wire 一次搬移一個單元,在退回率降到零的過程中 app replay 必須維持 100%,最後 app lift 留下一個純 Rust 應用程式。

副作用也算數。 忘了送出 webhook 或電子郵件的移植必須失敗。app record --effects http,smtp(或 --effect-env WEBHOOK_URL=http-url)讓應用程式連到本機替身,錄製每一個對外呼叫和郵件,--db-dump "sqlite3 app.db .dump" 則在每個請求之後錄製資料庫;replay 會檢查移植是否做了同樣的事。

app lift 在等什麼。 rust-anything obligations <repo> 列出原始程式提供的東西(匯出、命令、旗標、路由、環境變數、它刻意失敗的地方),--evidence 把每一項連結到涵蓋它的錄製案例。obligations --check 說明還有什麼在擋住 app lift:沒有案例涵蓋的項目、沒人認證過的類別、帶有 ... 行的預期檔案、前門走了卻沒有案例能解釋的退回。只有匯出能完整列出;其餘是偵測器辨識出的內容,由人來認證(obligations attest)或附上理由豁免某一項(obligations waive);每個決定都會寫一份 ADR。MCP 伺服器提供 obligations、obligations_check 和 obligations_fallbacks;前兩個只讀取,第三個只有在收到 write 或 inputs 時才寫入,它們都不會豁免、認證或把案例綁定到某項義務:決定權在你。用較早版本做的移植會在下一次 app lift 時停下,直到 obligations <repo> --check 什麼都不列出。

原始程式還在變? app drift 以錄製結果重播原始程式,列出現在回應不同的地方,GitHub Action 會在每次 push 時執行 gate。

由你做決定。 當你修正移植的行為時,rules --add "<rule>" 會保存它,之後每個代理提示都會包含它。rust-anything 寫入的所有內容都在 <repo>/rust/ 裡。

只看報告還是直接遷移,由你決定。 analyze 和 profile 只產生報告:一份依優先順序排列的移植計畫,以及真實負載下哪些程式碼最熱。它們是一般指令,所以報告不耗費 token。go 遷移一個單元:為最熱的函式建立橋接,錄製它,把移植交給你的代理,接著建置、比對並執行 gate,只有全部相符時才啟用(TS/JS、Python 和 PowerShell;disable 可以再關閉)。

一次執行要多久。 一次 go 執行移植一個單元,最多 --rounds 輪代理互動(預設 3):一輪用於移植,之後每次 diff 或 gate 失敗各一輪。整個應用程式就是每個單元執行一次,所以你可以在任何一次之後停下。

計畫用便宜的模型,移植用強的模型。 計畫不需要模型。移植時,傳入任何代理指令:rust-anything go --agent "claude --model <model>" -- <workload>。

代理。 rust-anything setup 會把它加到 Claude Code、Codex、Cursor、Gemini CLI 和 OpenCode 中。其他 MCP 用戶端可以執行 rust-anything mcp,這個 skill 也可以用 npx skills add erkamyaman/rust-anything 單獨安裝(見安裝)。

語言

語言 狀態 檢查對象
TypeScript/JavaScript 已驗證 ESLint, Prettier, json-server, Fuse.js, vercel/ms
Python 已驗證 CPython 的 colorsys(2,400/2,400 個案例)
Go 已驗證 Go 的 path(2,642/2,642)
Ruby 已驗證 Ruby 3.3 的 shellwords(1,617/1,617)
Java 已驗證 置於 facade 之後的 JDK 21(4,492/4,492)
C 已驗證 ffmpeg 的 libavutil、glibc
C# 已驗證 Google.Protobuf (2,941/2,941)
PHP 已驗證 PEAR XML_Util (1,838/1,838)
Kotlin 已測試 本儲存庫的測試 fixture,包括 Android
PowerShell 已測試 本儲存庫的測試 fixture
Swift 已測試 本儲存庫的測試 fixture

已驗證 指在別人寫的真實程式碼上完成了端到端移植;已測試 指由本儲存庫針對 fixture 的測試涵蓋。每次執行的日期和檢查方式:STATUS.md。

指令

指令 作用
rust-anything go -- <workload> 分析效能,為最熱的函式建立橋接,錄製它,把移植交給你的代理,執行 gate,然後啟用
rust-anything analyze <repo> 依優先順序排列的遷移計畫:單元、就緒程度、風險、相依套件
rust-anything profile <repo> -- <workload> 真實負載下哪些程式碼最熱,以及哪些該移植或批次呼叫
rust-anything bridge <repo> <unit> 含單一單元綁定的 Rust crate,stub 在 src/port.rs
rust-anything record <crate> 錄製原始程式的回傳值、拋出的例外和印出的輸出(--inputs、--from-tests、--pin-clock)
rust-anything diff <crate> 用 Rust 模組重播每個錄製的案例
rust-anything bench <crate> 在錄製的案例上為原始程式和 Rust 計時,包含橋接開銷
rust-anything fuzz <crate> 給兩邊餵新的輸入:找出錄製沒有涵蓋的部分
rust-anything gate <crate> 完成的定義
rust-anything selftest 在暫存資料夾中放入錯誤的移植,並檢查 diff 和 gate 是否都會拒絕
rust-anything enable / disable <crate> 把呼叫端切換到 Rust,或切回去
rust-anything report <crate> REPORT.md 和一張用於 pull request 的卡片
rust-anything app record / front-door / wire / replay / lift / drift 移植整個 CLI 或伺服器
rust-anything rules <repo> --add "<rule>" 你修正過的行為,之後每次移植都會保留
rust-anything map <repo> 每個單元、它的 crate、案例和最近一次 diff
rust-anything log <repo> 每一次啟用或關閉,以及每個 wire、lift 和 gate 的結果,來自 rust/audit.jsonl
rust-anything setup / doctor / mcp 為代理安裝、檢查執行環境、MCP 伺服器

授權條款

MIT © Erkam Yaman。你在自己儲存庫中產生的移植程式碼與產物均歸你所有。