- 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
Type annotations and basic types
This lesson covers Rust's basic types: i32, f64, bool, and &str.
Rust's type inference is strong enough that you can usually leave types out, but you can also annotate them explicitly by writing name: type. The most common are i32 (32-bit integer), f64 (64-bit floating point), and bool.
The sample code annotates its variables explicitly, as in let score: i32 = 85; and let average: f64 = 72.5;.
A common early stumble is trying to mix an integer type (i32) and a floating-point type (f64) in one calculation. Rust does not convert between different types automatically — you have to convert explicitly.
In professional work, spelling types out gives you fine control over the range of a number and how much memory it uses.
๐งช 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).
