Last week, I dived into the documentation. It was a bit long, and I decided to split my understanding into two different posts. Now is the time to finish them.
Threading
There's a single exercise for threads. It's a bit disappointing because it's a weak point of mine: I'd have loved more practice.
The solution is to wrap the JobStatus structure into a Mutex, just as the documentation describes. Mutex represents a global lock around an object. Please look at the above link for more details, which does a great job explaining Mutex in depth.
In general, I'm afraid of languages that offer macros. I think that macros decrease readability. Most macros are just a way to avoid duplicating code: other approaches achieve the same goal without the readability issue. Because Rust compiles to native code, most alternatives are not available. Hence, macros become a must.
The main problem of macro3.rs is that the code defines the macro in a dedicated module. The solution is more straightforward than what I tried first, namely use and prefix the macro with the namespace. You need to annotate the macro with #[macro_export]. Again, RTFM.
I couldn't solve macro4.rs without hints. I was missing the correct separator between arms. I tried previously with commas, like for match, but it failed, so I wrongly ruled the separator out.
The point of quizz4.rs is to (finally) write a simple macro. It's pretty straightforward with the example of the previous macros files. My issue laid in how to concatenate &str. You first have to own the left operand with the usage of to_owned().
Clippy
This series of exercises is pretty straightforward. But it allows us to know about Clippy.
No, I'm not talking about Microsoft Office's assistant from the 2000s.
The Clippy tool is a collection of lints to analyze your code so you can catch common mistakes and improve your Rust code.
π¦ Small exercises to get you used to reading and writing Rust code!
rustlings π¦β€οΈ
Greetings and welcome to rustlings. This project contains small exercises to get you used to reading and writing Rust code. This includes reading and responding to compiler messages!
...looking for the old, web-based version of Rustlings? Try here
Alternatively, for a first-time Rust learner, there are several other resources:
The Book - The most comprehensive resource for learning Rust, but a bit theoretical sometimes. You will be using this along with Rustlings!
Rust By Example - Learn Rust by solving little exercises! It's almost like rustlings, but online
Getting Started
Note: If you're on MacOS, make sure you've installed Xcode and its developer tools by typing xcode-select --install.
You will need to have Rust installed. You can get it by visiting https://rustup.rs. This'll also install Cargo, Rust's package/project manager.
MacOS/Linux
Just run:
curl -L https://git.io/rustlings | bash
# Or if you want it to