Learning Rust: The Rustlings
I started (re)learning the Rust programming language a couple of weeks ago. It’s my first new programming language in almost 10 years since picking up Go. After 10 years of writing primarily Go code, I wanted to try something new, and Rust was the logical next step for me.
Back in 2016 my team tried Rust to modernize a C codebase, but the implementation was still immature in 2016. It was hard linking it with our existing C codebase full of static variables. We abandoned Rust after a month and switched to Go. Despite the setback, I had good memories of working with Rust; the language was funky and clever, I liked the zero-cost abstractions, the powerful macros, and the built-in memory safety.
Fast-forward to today, and Rust is mature and ubiquitous. Many of my favorite tools are written in Rust like aichat, skim, fd, delta, and hyperfine.
Programming is a practical skill, the best way to learn a programming language is to use it and figure out how it works. Reading books and documentation doesn’t get you far without practice and experience.
There’s a series of exercises called Rustlings that teach Rust by making students complete Rust code listings. There are currently 94 exercises, each one taking between 5 and 15 minutes. Once an exercise is solved, the recommended solution is revealed. The Rustlings’ solutions are useful to see how idiomatic Rust compares to my own solutions; I noticed that idiomatic Rust is usually terser than my own code.
The exercises are limited in scope; it’s generally about fixing Rust compilation errors and creating minimal implementations. There’s not much programming; it’s mostly about syntax.
Each exercise’s source file has plenty of comments explaining the problem and how one can go about solving it. There are hints for each Rustling; they’re mostly pointing to the relevant documentation section or give pointers about how to solve the puzzle. I had to look at the documentation for about half of the exercises, and since the scope was limited it was generally quick to find the relevant information.
The Rustlings give you a broad overview of the language; covering every aspect without going deep. They are enough to give you a feel and basic understanding.
It took me around 12 hours to finish all the Rustlings exercises. I had fun, and I’m looking forward to doing more with Rust. After a decade without learning a new language, I’m excited to build something with Rust.