3 ms·
The same way you would write code written in 2021 over to Rust: by rewriting it from the ground up. Auto-translation won't work because Rust won't allow you to
by jandrese 5y ago
The same way you would write code written in 2021 over to Rust: by rewriting it from the ground up.
Auto-translation won't work because Rust won't allow you to build it in the same way you would have built it in C. It requires a full up redesign of the code to follow the Rust development model.
- masklinn 5y ago> Auto-translation won't work because Rust won't allow you to build it in the same way you would have built it in C. That is not entirely true, but if you translate the C code to Rust, you get C code, in Rust, with similar issues (or possibly worse). Of course the purpose would be to clean it up from there on, but it's unclear whether that's a better path than doing the conversion piecemeal by hand. The C2Rust people certainly seem to think so, but I don't know if there are good "client stories" about that path so far, whereas the manual approach does have some (e.g. librsvg), though it's not for the faint of heart.
- lucb1e 5y ago> That is not entirely true, if you translate the C code to Rust, you get C code, in Rust, with similar issues (or possibly worse). thus it was basically true after all? Like, sure, Rust is turing-complete so you can simulate whatever C did and thus technically you can translate anything that C can do into Rust. But if it doesn't fix any problems, then have you really translated it into Rust?
- masklinn 5y ago> thus it was basically true after all? No? > Like, sure, Rust is turing-complete so you can simulate whatever C It's not simulating anything, and has nothing to do with turing completeness. > But if it doesn't fix any problems, then have you really translated it into Rust? Yeees? Unless your definition of "translated" has nothing to do with the word or the concept. You end up with a project full of rust code which builds using rust's toolchains. That sounds like a translation to me.
- saagarjha 5y agoThe jury's out on whether Rust code with unsafe around all of it is better than C. It's good that you can slowly reduce the unsafe, which is not something you can do with C, but the code is frequently harder to read and may have new bugs.
- masklinn 5y ago> The jury's out on whether Rust code with unsafe around all of it is better than C. The goal definitely isn't to keep it as is, the entire point of C2Rust is to provide a jumping point then not have to shuffle between the two as you perform the conversion.