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.

2.3 KB
Raw Blame

Examples and case studies

Real modules ported with rust-anything, with the commands and the numbers. Back to the README.

Case study: x18n's core

All 29 functions of x18n's core that can move without an API change were ported with rust-anything: every gate passes and 9,582 recorded cases match exactly. rust-anything bench then showed the ports are slower than the TS as called from JS, because the bridge costs more than the work. Full report: demo/x18n-core. The lesson is built in: measure with bench before shipping a port.

Real code in eight languages

Go's path, Ruby's shellwords, Python's colorsys, JDK and glibc behavior behind small facades: every port passes its gate, 13,010 recorded cases in all. The runs found and fixed bugs in rust-anything (floats off by one ULP through serde_json, C crashes during recording, untyped code getting garbage inputs). Called per function, the Ruby port runs 4.4x faster than Ruby and the Python port 1.35x faster than CPython, while Go and Java leaf functions stay faster in their own language. The Go and Java batch speedups first published here were withdrawn: the Java original measured faster than the Rust batch under JMH (see the correction in docs/real-world-languages.md). Report: docs/real-world-languages.md.

Example: a real module from x18n

packages/core/src/fuzzy.ts from x18n, ported both ways in demo/:

rust-anything analyze ../x18n                                      # fuzzy.ts: ready, wasm-bindgen (core runs in browsers)
rust-anything bridge ../x18n packages/core/src/fuzzy.ts --out demo/fuzzy-rs
rust-anything record demo/fuzzy-rs --count 2000
# write src/port.rs
rust-anything gate demo/fuzzy-rs

A first port that indexed by Rust char passed simple tests but failed diff:

198/200 cases match
- fuzzyScore("b๐Ÿ˜€", "a๐Ÿ˜€b๐Ÿ˜€c"): expected {"ok":1997}, got {"ok":1998}

JS indexOf counts UTF-16 code units, so an emoji is two positions. The port in demo/*/src/port.rs uses the generated utf16 helpers and passes 2000/2000 cases and the gate, as napi-rs (demo/fuzzy-napi) and as wasm-bindgen (demo/fuzzy-rs).

The plan rust-anything writes for all of x18n: docs/examples/x18n.md.