One-Week Rust Learning Program
If you want to learn Rust, you need some guidance on what to do, what to learn.
Here's how I've been approaching it, based on feedback from our Rust study group.
Start with the official Rust language book.
It's about 20 chapters.
Ideally, I want to breeze through it in about a week, so I can get down to writing Rust ASAP. I'm not looking for deep mastery here, just enough to learn my way around and not be lost.
One approach would be to skim or fast-read 4 per section, meaning it's broken up into 5 blocks.
That way, in about a week, you can have basic familiarity with the language.
However, since some chapters are a lot more important than others, I'm using a modified reading version for the book.
This is the recommended chapter reading 'lite' version, if you just want the essentials (thank you to John A. for providing this).
1-6, 8, 10, 12.1, 12.2, 13, 15?, 16?, 18
This makes your life a lot easier: you can finish it in about a week.
Breaking into 7 sections, that would be:
1. Getting Started
This basically tells you how to get Hello, World running.
It also explains .toml, the markup language you use to specify dependencies.
2. Programming a Guessing Game
This goes one step beyond that: taking user input and comparing it to a randomly generated number, in a loop, until you guess the number, with some error checking (user has to enter a number).
3. Common Programming Concepts
Variables are immutable by default, but you can make them mutable by prefacing them with mut.
Rust is statically typed. What does that mean? It means the compiler must know the types of all variables at compile time.
Use snake case for functions and variables.
4. Understanding Ownership
In Rust, each value has a variable that’s called its , there can only be one owner at a time (trying to have more than 1 will cause compiler errors), and when the owner goes out of scope the value will be dropped (which is why you can have 'shadowing').
At any time you can have one mutable reference or multiple (infinite) immutable references - but whatever they are, they must always be valid.
If you want to copy something in Rust, to avoid referencing issues, consider using clone.
5. Using Structs to Structure Basic Data
Structs are conceptually not too hard to understand.
One tricky part: they have to take String because of the lifetimes issue.
Methods are similar to functions in that they're defined with the fn function, but different in that their defined in the context of a struct and their 1st argument is self.
The impl method is explained here.
6. Enums and Pattern Matching
You can use the Some value to hold values, of type T or generic type.
You can use match with enums.
8. Common Collections
10. Generic Types, Traits, Lifetimes
12. Functional Language Features
13. Using Cargo
14. Smart Pointers
15. Featureless Concurrency
16. Object Oriented Programming
18. Patterns and Matching