Learn Rust
Write, read and test small Rust programs: ownership, borrowing, enums, Result and ?, traits, lifetimes, iterators and a tested command-line tool.
Rust · Beginner · 10 lessons · 113 min
First steps
2 lessons
- 8 minBeginner
Install Rust and run your first program
Install Rust with rustup, create a project with cargo new and run it with cargo run. See what fn main and println! do and how run, build and check differ.
- 10 minBeginner
Variables, mut and shadowing in Rust
Learn why let variables are immutable, add mut to change one, use const and see how shadowing differs from mut. Fix the error for assigning twice.
Ownership and types
3 lessons
- 10 minBeginner
Ownership and moves in Rust
Learn the three ownership rules, how a String moves when you assign it or pass it to a function, and when to clone. Fix a use of a moved value.
- 10 minBeginner
Borrowing and references in Rust
Use & to borrow a value and &mut to change it without moving it. Learn the rule of one mutable or many shared references, and fix two overlapping borrows.
- 12 minBeginner
Structs, enums and match in Rust
Define structs with methods in an impl block, enums that carry data, and use match and if let to handle every case, including Option. Fix a missing arm.
Errors and traits
2 lessons
- 12 minBeginner
Option, Result and the ? operator in Rust
Handle a missing value with Option and a failing call with Result, and pass errors up with the ? operator. Fix ? used in a main that returns nothing.
- 12 minBeginner
Traits in Rust: shared behaviour
Share behaviour between types with traits: default methods, trait bounds, derive, Display and Box<dyn Trait>. Fix a type that is missing its impl.
Lifetimes, iterators and projects
3 lessons
- 12 minBeginner
Lifetimes in Rust: how long a reference lives
See how lifetimes tell the compiler how long a reference is valid: longest, structs that hold a reference and elision. Fix a missing lifetime specifier.
- 12 minBeginner
Iterators and closures in Rust
Write closures that capture variables and chain iterator adapters such as map and filter. See why iterators are lazy and fix a use after into_iter.
- 15 minBeginner
Crates, modules and cargo test
Split code into modules, make items pub, write unit tests and run cargo test. Fix a private function, then build a small tested command-line tool.
Free AI coding tools to practise with
- AgentRouter Free Credits
Free AI coding credits: $25 per daily check-in and $50 per invite
No cardVerified
- Cline Free Models
Try select models free in Cline via rotating promotions with a usage quota
No cardVerified