Code Lab
Rust Anything Tested: How to Pick the First Python Module to Port
CODE LAB · PROJECT SPOTLIGHT
Rust Anything Rust · MIT / Apache-2.0
Plan a migration and check each Rust port against recorded behavior.
Project artwork by Erkam Yaman and contributors.
Which module should you move to Rust first? Rust Anything reads a source tree and ranks the candidates. We tried its planner on a Python invoice calculator. Adding one test file raised the module’s priority from 74 to 91 while its production code stayed identical. What changed was the evidence available to someone planning the port.
What the planner saw in four lines of Python
Our example totals an invoice in integer cents. Save the two functions below in invoice.py in an empty directory. Three items at 125 cents each and another at 25 cents add up to 400 cents. An empty invoice totals zero. Both are observable behaviors a future port should preserve.
def line_total(quantity, unit_cents):
return quantity * unit_cents
def invoice_total(lines):
return sum(line_total(q, price) for q, price in lines)
We used the Windows x86-64 binary from release v5.0.2. With the executable on your path, run this command from the example directory. The final dot selects the current directory. It prints a Markdown report, or you can add --json to compare reports in a script.
rust-anything analyze --lang python .
The first run recommended a PyO3 bridge, the layer through which Python could call Rust. It flagged two dynamically typed functions and found no tests. We added test_invoice.py, imported invoice_total directly and wrote two assertions for the inputs above. Both passed under python -m unittest -v. We then ran the same planner command in the same directory.
| Planner output | Invoice module alone | With the test file |
|---|---|---|
| Priority | 74 | 91 |
| Readiness | 97 | 100 |
| Test files | 0 | 1 |
| Suggested bridge | PyO3 | PyO3 |
Why one test file changed the score
The excerpt assigns a ten-point bonus when a test imports the unit directly. A test elsewhere in the same package earns four points. The next expression caps readiness at 100, which explains why our 97 rose by just three points. Priority has a separate calculation that also rewards direct tests. The planner counted one test file even though the test runner executed two cases. Read the readiness calculation · Read the priority calculation.
A readiness score of 100 still leaves a business question. What should happen to a negative quantity representing a return? Our two tests leave that open. Record the current result and decide whether callers depend on it before translating the function. Our local exercise covered the planner and Python tests. We did not run a Rust port or measure a speedup.
When is the rewrite worth doing?
The maintainer’s terminal demo shows the evidence you would want next. A profile puts the TypeScript fuzzyScore function at 180 ms in an 862 ms run. Because the caller invokes it once per item, the tool suggests sending a batch across the language boundary. Later in the demo, the project’s verification command reports 2,000 matching recorded cases. The profile tells you where time went. The replay tells you whether those callers received the same results after the port.

If you already know which function is slow, our Fast-Anything walkthrough follows a recorded Python call through a Rust comparison. Rust Anything’s planner is useful a step earlier, when you need to choose a unit and identify the tests that protect it. The planner runs locally without a model account. Later steps can invoke a coding agent and build Rust bindings, so their toolchain requirements and costs depend on your choices.
Source excerpt and demo by Erkam Yaman and the Rust Anything contributors. MIT license · Apache 2.0 license · Mindung’s overview at 2:42.
