Tech News

rust-anything: The Open Source Tool Helping AI Agents Rewrite Apps in Rust

19 times faster. That is the measured gain on Prettier, the code formatting tool, after it was rewritten in Rust with rust-anything. This open source project lets an AI agent write the Rust code, then checks that the new version behaves like the old one.

Rust is clearly the programming language du jour, and one real trend is to rewrite existing software in Rust. Want a recent example? I'd point to Discord currently rewriting its apps in Rust. If that is what you are planning to do, then this GitHub repository may interest you: rust-anything. This open source project, released under the MIT license, is not even a month old, and yet it already has nearly 8,500 stars.

So, rewriting an application in Rust is a trend. But the hard part is making sure nothing breaks along the way, and that is exactly what rust-anything is designed to do. That said, it is not here to convert every line of code: writing the Rust code is up to your AI agent (Claude Code, Codex, Cursor, Gemini CLI or OpenCode), or to you. rust-anything provides the framework: the Rust version is only swapped in once it has been proven to produce the same results as the original code.

How does rust-anything work?

Here are the steps involved when using rust-anything:

  • A reference: with record, the tool runs the original program (generated edge cases, known pitfalls, examples you provide) and keeps track of every result.
  • A bridge between the two languages: bridge creates the Rust project and an adaptation layer (PyO3 for Python, napi-rs for Node.js, etc.), exposing the Rust functions under the same names and with the same parameters as the originals. The rest of the code calls them without any changes.
  • An arbiter: diff compares the Rust version against the recording, case by case, then gate closely inspects the port (tests, unsafe code audit). At the slightest mismatch, it stays disabled.
  • A gradual switch: for an entire application, a Rust entry point sends anything that has not yet been ported back to the original program. Components move to Rust one after another, and app lift ends up producing a 100% Rust application.

In practice, you can choose to rewrite all or part of a program. For that, rust-anything's go can launch your program and measure what consumes "execution time" so you can target optimizations at the slowest functions rather than at the whole codebase.

On the source language side, the tool already supports a solid list: TypeScript/JavaScript, Python, C, Go, Ruby, Java, and Kotlin. However, support for PHP and C# is still more limited. On the AI side, integration with AI agents goes through an MCP server and a skill.

Prettier, json-server, ESLint: real-world ports

To show that the method holds up, the author applied it to well-known projects. Here are some of the tests:

  • Prettier: from the command line, with one process per file, formatting 2,360 JavaScript and TypeScript files takes 6.9 seconds, versus 128.6 seconds with the original tool. Most of the gap comes from Node.js startup, which is avoided for each file: once Prettier is loaded into memory, the gain is 4.2x.
  • json-server: this REST API server written for Node.js becomes a single Rust binary, using 3.5 MB of idle memory compared with 74 MB.

Want to try it on your machine? Note that binaries are available for Windows, Linux and macOS, as well as an npm package. You can also install it with the cargo install rust-anything command (Cargo being the Rust package manager you need to install first), followed by rust-anything setup.

I tested rust-anything on a Python program

To see what the tool does, I tried it on my Mac with a small Python application. It reads a fake SSH log (auth.log) with one million lines and sorts IP addresses based on failed login attempts, including the number of targeted accounts and the peak number of failures per minute.

The first lesson from this test: code structure matters. Initially, my analysis function was in the same file as the code that launches the program, and go refused to port it to Rust: in its view, it was part of the entry point, which must remain in Python. Once the function was moved into a separate module, everything followed: function selection, recording of 210 cases, Rust code written by Claude Code, then 210 out of 210 cases matching, which made it possible to validate gate.

Here is its output, without Claude Code's report or the results displayed by the program:

go: profiled `python3 analyse.py petit.log` (89 ms): porting `analyser` (detection.py:7), 63% of the run, the outermost portable function
go: bridged analyser (Pyo3) at [...]/rust/analyser-rs
go: captured 1 real call(s) from the workload
go: recorded 210 case(s) (0 throw in the original)
go: handing the port to `claude` (turn 1 of 3)
go: diff: 210/210 cases match
go: gate passed
go: bench: 1.4x faster as its callers call it, call included
go: switched on: analyser runs in Rust now ([...]/detection.py)

The "1.4x" from bench is an average across the recorded cases. On the one-million-line file and for the full program, here are the times I measured (median of three runs):

VariantTotal timeGain
Original Python0.42 sBaseline
Rust function, taking the list of lines0.35 s1.2x
Rust function, taking the file as a single string0.23 s1.8x

That is far from a huge gain, but at the same time, this was only a test on a small program where I mainly wanted to see the process. This approach should deliver convincing results with a real program that you are trying to optimize, beyond its complexity. If you tested it and want to share feedback, feel free to comment on this article.

author avatar
Florian Burnel Co-founder of IT-Connect
Systems and network engineer, co-founder of IT-Connect and Microsoft MVP "Cloud and Datacenter Management". I'd like to share my experience and discoveries through my articles. I'm a generalist with a particular interest in Microsoft solutions and scripting. Enjoy your reading.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.