Site like rustbyexample.com, but with examples in both C and Rust?


#1

I’m looking for a site showing how to do something in C, and then showing how to do the exact same thing in Rust.

I’m thinking coding examples with three columns would be optimal:
Column 1: Best practise C
Column 2: Non-idiomatic Rust that looks as much as the original C example as possible, only using core
Column 3: Best practise Rust written in idiomatic style using features from std when appropriate

If such a site exists, I think it would be a good way for C coders to learn Rust,
in a step by step way, where they could first learn how to write non-idiomatic Rust code,
that looks very much like C, and then they can gradually learn the more advanced
features in Rust that don’t exist in C.

I’m only a beginner C coder myself, but I would personally have much use for such a site,
since it would allow me to understand how to rewrite the non-idiomatic C code
generated from the C-to-Rust conversion tool “corrode”: https://github.com/jameysharp/corrode

The author of Corrode says he encourage someone to write a tool that would translate
the non-idiomatic Rust code into idiomatic Rust, and it makes sense to write a separate tool
for that, as then such as tool can be used to improve both Corrode-output but also
other Rust code written by C developers who are beginners in Rust and still
write Rust code that looks like C.


#2

It’s not exactly what you’re looking for, but have you visited http://rosettacode.org/wiki/Rosetta_Code? I don’t think the examples are official, but they could be a good starting point to compare the same tasks performed in C and Rust.


#3

Thanks a lot! Very useful!


#4

If you want a more easy way to compare the code, try

https://rosetta.alhur.es

Simply select both languages you want to compare and it will display the rosetta code tasks next to each other.