4 ms·
As someone who's rewritten several things in Rust, and even written C to Rust "transpiler", I totally agree with the approach of keeping working C code as-is, a
by pornel 8y ago
As someone who's rewritten several things in Rust, and even written C to Rust "transpiler", I totally agree with the approach of keeping working C code as-is, and switching to Rust for new code.
Rewrites from scratch are time consuming, and at risk of second system syndrome (especially when you suddenly have all the shiny new language features).
Direct 1:1 rewrites are underwhelming. After the initial C to Rust pass you end up with the same program, with a C-like architecture, and all you've done is replaced gcc with a slower rustc.
But wrapping a C implementation in a Rust API works great. You can translate C's implied ownership semantics into explicit Rust types. You can wrap all these C structs/handles with their init and free functions into RAII that never leaks.
It's something you can do in days, not months to years. You keep a fully working program at all times. You benefit from Rust for new development, and you can gradually refactor C out of it when and where it's sensible to do so.