- 01Setting up (what you'll need)
- 02Your first output (println!)
- 03Variables and mutability (let / mut)
- 04Type annotations and basic types
- 05Branching (the if statement)
- 06Repeating (the for loop)
- 07Writing your own function
- 08Repeating (while and loop)
- 09Ownership, the basics
- 10Borrowing (references, &)
- 11Working with vectors (Vec)
- 12Structs
- 13enum and the match expression
- 14The Option type (null safety)
- 15The Result type and error handling
- 16Traits
- 17Generics
- 18Closures
- 19Working with strings (String)
- 20[Project] Build a small inventory system
Variables and mutability (let / mut)
This lesson covers how Rust declares variables and what it means for one to be mutable.
You declare a variable with let, but by default its value cannot be changed afterwards (it is immutable). To allow changes you must write let mut, explicitly declaring the variable mutable.
The sample code declares an immutable let name = "Alice"; and a mutable let mut age = 14;, then changes only age.
A common early stumble is trying to change a variable without mut and hitting a compile error. This immutable-by-default design heads off bugs where a value gets overwritten by accident.
In professional work, the habit of adding mut only to the variables that genuinely need to change leads to code with fewer bugs.
๐งช This site can't compile or run Rust directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ nothing is sent anywhere).
