Engineering & AI

rust-anything: porting an app to Rust piece by piece with an AI agent

rust-anything guides AI agents through porting parts of an app to Rust so developers can catch behavior changes before replacing the original code.

Summary

  • Port a measured bottleneck, then compare its output and speed with the original before replacing it.
  • Only move heavy code you have measured; porting small functions one by one is usually slower.
  • Ship a port only when diff matches every case, bench is faster and gate passes.
rust-anything: porting an app to Rust piece by piece with an AI agent

You have measured a slow part of the app, but porting it to Rust could change results users already depend on. rust-anything helps you try replacing that piece and compare its behavior and speed on the same inputs before deciding whether to use it.

Based on the project's documentation and benchmarks, version 1.4.0 (18 November 2026). HubCom has not used this tool in a client project.

How does the Rust version get checked against the original?

  • It does not translate code. Your AI agent, or a developer, writes the Rust.
  • It records the original's behavior on many edge cases, then replays each case against the Rust.
  • It generates a bridge so the rest of the code calls the Rust without an API change.
  • It measures first: it finds the functions that take the time and the loops worth moving.
  • A final gate: a port is done only when every case matches and fmt, clippy and tests pass.

It supports TypeScript/JavaScript, Python, C, Go, Ruby and Java, with PHP and C# in preview. It plugs into Claude Code, Codex, Cursor and Gemini CLI through MCP.

When to use it

  • Use it when you have measured a heavy piece of code, such as search, string processing or parsing over many items.
  • Use it when someone on the team can read and maintain Rust after the move.
  • Skip it when the slowness comes from the database, the network or an external API. A new language does not fix those.
  • Skip it for an ordinary CRUD app with no performance problem.

Caveats

  • Porting small functions one by one is usually slower, because crossing the bridge costs more than the work itself. In the project's x18n case study, 29 functions passed the gate with 7,925 matching cases and were still slower than the TypeScript.
  • Moving a whole loop is what pays off. Batch mode hands the data to Rust once and runs it on every core. Searching 50,000 keys went from 10 ms to about 0.5 ms on 4 cores.
  • It only catches what the recording covers. Behavior outside the recorded data is not checked.
  • The project is very new. It launched on 16 November 2026 and releases often, so pin the version you use.

Trial setup

Before you try it, prepare this for your AI agent:

  • A real workload to profile, not a toy example.
  • The goal: speed up one hot path, or move the whole app.
  • Real input data to record, on top of the generated edge cases.
  • The bar: how much faster a port must be before it is worth shipping.

Port one measured bottleneck

  1. Install it and register it with your agent: cargo install rust-anything, then rust-anything setup.
  2. Profile with rust-anything profile on the real workload.
  3. Generate the bridge for the hot path with bridge. Add --batch when the function is called in a loop.
  4. Record the original's behavior with record, including real data.
  5. Let the agent write port.rs, then run build and diff until every case matches.
  6. Measure again with bench. If it is not faster, stop and do not ship it.
  7. Run both side by side with shadow on real data, then run gate.

Common pitfalls

  • Skipping the profile, then porting a function that never took the time.
  • String positions drift: JavaScript counts UTF-16 code units, Rust counts UTF-8 bytes. An emoji shifts positions; the project hit exactly this bug in its x18n example.
  • Trusting hand-written tests. Only diff against the recording proves the behavior matches the original.
  • The agent swallowing errors with unwrap. The gate blocks this where the original returns an error.
  • setup edits your agent configuration. The old file is saved as .rust-anything.bak; undo it with setup --remove.

Does the Rust version match the output and run faster?

  • diff reports that every recorded case matches.
  • bench is faster than the original, bridge cost included.
  • shadow reports no mismatch on real data.
  • gate passes in full.

Out of scope

Moving a whole app to pure Rust (app front-door, app wire, app lift) and porting HTTP servers. These need their own architecture decisions; see the "Port a whole app" section of the project documentation.

Terms in this article (5)
rust-anything
An open-source tool that helps an AI agent move an app to Rust piece by piece and checks it against the original's behavior.
Rust
A compiled programming language that runs close to C/C++ speed and is memory-safe without a garbage collector.
MCP (Model Context Protocol)
An open protocol that lets AI agents call outside tools. rust-anything uses it so Claude Code, Codex, Cursor and Gemini CLI can drive it.
Claude Code
Anthropic's coding agent, running in the terminal and in IDEs.
Codex
OpenAI's coding agent.

Frequently asked questions

Does rust-anything translate code to Rust by itself?

No. An AI agent or a developer writes the Rust. The tool profiles, generates the bridge, records the original's behavior and checks the Rust against that recording.

Which languages does rust-anything support?

In version 1.4.0: TypeScript/JavaScript, Python, C, Go, Ruby and Java. PHP and C# are in preview.

Is a Rust port always faster?

No. Calling small functions one by one across the bridge is often slower than the original. Moving a whole loop in batch mode is clearly faster.

Sources

Talk with HubCom ↗