AIFeed

用 AI 编程代理将代码库迁移到 Rust

Translation(model translation, not the source's own text)

Rust Anything

用你的编程智能体把应用移植到 Rust,并验证移植后行为仍然一致。免费开源,在你的机器上运行,无需账号。

crates.io version
crates.io version
npm version
npm version
GitHub stars
GitHub stars
crates.io downloads
crates.io downloads
npm downloads
npm downloads

13.8K GitHub stars · 1.1K forks · 86 contributors(读取于 2026-12-04)· Trendshift 当日和当周排名第一的 Rust 仓库 · 今日在 Product Hunt 上线

Rust Anything 内部没有翻译器。你的编程智能体负责编写 Rust。Rust Anything 记录原始代码的行为,对移植版本重放每一个记录用例,只有当所有用例都匹配时才判定移植完成。文档
analyze plans what to port; rust-anything go bridges, records, lets your agent port and gates the result
analyze plans what to port; rust-anything go bridges, records, lets your agent port and gates the result

目录:Why · Install · Try it · Results · How it works · Languages · Commands · Security and privacy · Consulting · Sponsors · License · Community

Why

编程智能体让重写变得廉价。难的是之后那个问题:Rust 版本是否一致?相同的输出、相同的错误、相同的边界情况。

  • 完成意味着行为一致,而不是「能编译」。只有当所有记录用例都匹配,并且 cargo fmt、clippy、cargo test、unsafe 检查与 stub 检查都通过时,gate 才会通过。
  • 一次一个函数。调用方保持相同的 API,应用的其余部分留在原地,disable 可随时回退。
  • 也支持整个应用。一个 Rust 前门立于 CLI 或服务器之前,把每个请求发送给 Rust 或原始版本,因此应用在每一步都能工作。
  • 在你的机器上运行。无遥测,无账号。plan(analyze)不需要模型,也不消耗 token。
  • 在真实代码上验证过。Prettier:17,224 次记录运行中 17,224 次字节完全一致。ESLint:10,585 次中 10,585 次。ffmpeg 的 libavutil:226,447 次记录调用中 226,447 次。见 Results。

Install

把这段粘贴到你的编程智能体中:


        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   # or: npm install -g rust-anything
rust-anything setup           # adds it to Claude Code, Codex, Cursor, Gemini CLI and OpenCode
rust-anything doctor          # checks the runtimes your original needs, with the fix for each
      

或者用包管理器(.deb 附在每个 release 中;更多见 install):


        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
      

智能体:阅读 rustanything.ai/llms.txt 获取安装步骤、所有命令以及移植工作流。

Try it

安装后,把这段连同你应用中运行缓慢的命令一起粘贴到你的智能体中:


        Run rust-anything go -- <slow command of this app> and finish the port until rust-anything gate passes.
      

go 会对工作负载进行剖析,选出可移植的最热函数,为其建立桥接、记录它的行为、把移植交给你的智能体并对其进行 gate 校验。想先看计划?rust-anything analyze . 会给出可移植项与风险项的排名列表,不需要模型,也不消耗 token。

结果

真实代码由他人编写,跑过 Rust Anything。每一行都链接到完整运行记录,包含日期、命令和途中失败的用例(所有运行)。

项目迁移内容行为速度
PrettierJS、TS、JSON、GraphQL、YAML、Markdown、CSS、SCSS、Less17,224/17,224 字节级完全相同,其中 15,861 个完全用 Rust 实现命令行处理 59 个真实文件:3.63 秒降至 0.20 秒,18 倍(主要是 Node 启动开销;进程内每文件约 7 倍)
ESLint检查器核心和 90 条规则,置于 Rust 前门之后10,585/10,585 的 stdout、stderr 和退出码字节级完全相同,其中 10,204 个完全用 Rust 实现
ffmpeg libavutil10 个可移植 C 的 crate226,447/226,447 条记录的调用
json-server整个服务器,提升为 5.3 MB 的 Rust 二进制514/514 条记录的请求GET /posts ,50 个连接:19.7k 提升至 115.0k 请求/秒
Fuse.js模糊搜索3,414/3,41450,000 个字符串:全核 32 倍,单核 5.3 倍
vercel/msparse 、 format975/975,包括来自其自带 Jest 测试的 340 次调用批量 parse x100,000:18 倍

Rust 并不会自动更快。一个通过桥接逐次调用的小函数往往比 JIT 慢,bench 展示了这一点。只迁移热点,或者将其批处理。

工作原理

什么算完成。看行为,而不是你的测试。record 在生成的输入和给定输入上运行原始代码,并保存每次调用返回、抛出和打印的内容。当 gate 通过时,迁移即完成:每个记录的用例都匹配(错误必须具有原始代码的类型;其消息文本不进行比较),并且 fmt、clippy、cargo test、unsafe 检查、stub 检查以及检查记录答案是否被粘贴进迁移代码中的检查全部通过。你自己的测试也会运行。

你的测试成为用例。record --from-tests -- npx jest(或 pytest)运行原始代码自带的测试套件,并记录它对单元发出的调用。--pin-clock 在两侧固定时钟和随机数(TS/JS 通过 napi 桥接,以及 Python),以便依赖日期的代码可以匹配。参数包含函数、符号、循环引用、RegExp 或 Error 的调用不会被 --from-tests 记录。

迁移整个应用:analyze 制定计划,你敲定决策,app record 捕获其真实行为,前门在原始代码前面运行 Rust,单元逐个迁移过去,直到没有任何回退,然后 lift 留下一个纯 Rust 应用
迁移整个应用:analyze 制定计划,你敲定决策,app record 捕获其真实行为,前门在原始代码前面运行 Rust,单元逐个迁移过去,直到没有任何回退,然后 lift 留下一个纯 Rust 应用

整个应用:命令行工具和服务器。app record 记录一个命令行工具(退出码、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 检查迁移代码做了相同的事。

把代码库移植到 Rust:借助 AI 编码智能体

app lift 在等待什么。rust-anything obligations <repo> 列出原始项目所提供的全部内容(导出、命令、标志、路由、环境变量、以及它故意失败的位置),--evidence 会把每一项关联到实际执行它的已记录用例上。obligations --check 指出还有哪些内容阻碍 app lift:某个条目没有被任何用例执行、某个族没有任何人确认、某个预期文件里有一行 ...、或者前门选取了一条没有任何用例能够解释的 fallback。只有导出项可以被完整列出;其余内容取决于探测器识别到了什么,并由人来确认(obligations attest),或者附上理由予以豁免(obligations waive);每一次决策都会写入一份 ADR。MCP server 提供 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/;enable 会用一段可移除的代码块修改原始项目的文件,setup 则写入你的智能体配置。

报告还是迁移,由你选择。analyze 和 profile 只做报告:一份按优先级排序的移植计划,以及在真实负载下哪些部分是热点。它们是普通命令,所以生成报告不消耗 token。go 迁移一个单元:它会桥接最热的函数、录制它、把移植交给你的智能体,然后对它执行构建、diff 和 gate,只有一切匹配时才会启用它。它需要 profile,因此可运行于 TS/JS、Python、Go、Ruby 和 Java;对 TS/JS 和 Python 它是原地启用的(disable 会把它关回去),对其余语言则在 gate 和 bench 之后停下。PowerShell 单元需要手动走一遍 bridge、record、diff、gate 和 enable:profile 不运行 PowerShell。

一次运行要多久。一次 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(见 install)。

语言

语言状态验证于
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已验证门面之后的 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已测试本仓库的 fixtures;在一台电视上的 Android,291 个用例中匹配 279 个,12 个未调查
PowerShell已测试本仓库的 fixtures
Swift已测试本仓库的 fixtures

已验证意味着在他人编写的真实代码上端到端地完成移植;已测试意味着由本仓库基于 fixtures 的测试覆盖。每一次运行,包括日期与验证方式:docs/STATUS.md。

命令

Command作用
rust-anything go -- <workload>对热点做 profile,桥接最热的函数,录制它,把移植交给你的 agent,通过 gate 校验,然后启用
rust-anything analyze <repo>排序后的迁移计划:单元、就绪度、风险、依赖关系
rust-anything profile <repo> -- <workload>真实负载下哪些是热点,以及要移植或批量处理什么
rust-anything bridge <repo> <unit>为一个单元生成带 bindings 的 Rust crate,桩代码放在 src/port.rs
rust-anything record <crate>记录原实现返回什么、抛出什么、打印什么( --inputs 、 --from-tests 、 --pin-clock )
rust-anything diff <crate>用 Rust 模块重放每一条已录制的用例
rust-anything bench <crate>在已录制的用例上对原始实现和 Rust 计时,含 bridge
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为 agent 安装、检查运行时、MCP server

Security and privacy

录制会运行原实现的真实代码。请在副本上操作,并让服务器指向测试数据库。record --sandbox 和 app record --sandbox 会在无网络、仓库只读和 CPU 限制下运行它(macOS 上用 sandbox-exec,Linux 上用 bubblewrap;doctor 会检查它)。macOS 上没有内存限制,Linux 这条路径尚未运行过(见 STATUS)。

rust-anything 在你的机器上运行。CLI、MCP server 和 skill 不会把你的任何代码、录制内容或结果发送到任何地方,不收集任何遥测数据,也不需要账号。会访问网络的是你或你的 agent 所运行的东西:Cargo、你的原实现所需的包管理器,以及 gate 运行 cargo deny 或 cargo audit 时的 RustSec 数据库。详情:Privacy。

Consulting

要把代码库迁移到 Rust 吗?我提供 Rust 迁移咨询服务:[email protected]

Sponsors

Made in Türkiye 🇹🇷 by erKam Yaman X: @RustAnything · @erkamyaman_ng Rust Anything 是自由且开源的。如果它对你有帮助,赞助能让它持续下去。

你的安全是第一位的:赞助者会在这里获得一个 logo 和一个链接,并在社交媒体上获得一次提及。不提供付费推荐,也不提供面向第三方 AI API 经销商的搭建指南,所以这里不会有任何东西把你的代码、密钥或数据引向你并未选择的去处。

不存在 Rust Anything 币或代币。任何提供或出售此类东西的人都不隶属于本项目或我本人,所以不要相信任何使用这些名字的可疑或来路不明的东西。

Company sponsor: CodeRabbit
Company sponsor: CodeRabbit
Domain sponsor: Atak Domain
Domain sponsor: Atak Domain
Sponsors: Santosh Yadav, Hakan Soytürk, Ali Yilmaz, Ashley Hunter, Fatih Uzuntaş, bugrcvi, starwish.ing, omerrgoren
Sponsors: Santosh Yadav, Hakan Soytürk, Ali Yilmaz, Ashley Hunter, Fatih Uzuntaş, bugrcvi, starwish.ing, omerrgoren

以公司身份赞助,或有其他问题?[email protected]

License

以 MIT 许可授权。© Erkam Yaman。你仓库中的移植和生成代码归你所有。

除非你明确声明 otherwise,你为纳入 rust-anything 而有意提交的任何贡献均以 MIT 许可授权,不附加任何额外条款或条件。

Community

有关问题和想法,请到 Discord 交流。Bug 和功能请求请提交到 issues;刚接触这个仓库?可以先从一个 good first issue 开始。

每位贡献者都会获得徽章,以及用自己语言制作的分享卡片:找到属于你的那一份。

The translation is machine-generated and individual terms may be off. Nothing is rewritten or cut; the original is authoritative.

Published by HN AI
This site only summarises and aggregates; copyright stays with the original author. Headlines and summaries follow the source — where they differ, the original wins.
Read the original ↗