1. Meet Rust and its toolchain
BeginnerUnderstand Rust's goals, compile a small program, and use Cargo and compiler messages confidently.
Your first Rust program
A Rust executable begins in the main function.
Create a project with Cargo
Cargo manages Rust projects, builds, dependencies, and tests.
Formatting and compiler feedback
Use standard formatting and treat errors as guidance about program structure.
Module checkpoint: Create a Cargo project, print three lines, run cargo fmt and cargo check, then fix one deliberate syntax error by following the compiler diagnostic.
2. Variables, types, and constants
BeginnerLearn mutability, scalar and compound types, type inference, and explicit conversions.
Bindings and mutability
Rust bindings are immutable by default unless declared with mut.
Scalar types and inference
Integers, floating-point values, Booleans, and characters represent common scalar data.
Constants, tuples, arrays, and shadowing
Constants, tuples, arrays, and shadowing provide different ways to express stable or grouped data.
Module checkpoint: Write a small program containing a constant, a mutable counter, a tuple, and an array. Print selected values and explain why each type fits its role.
3. Expressions, decisions, and loops
BeginnerUse Rust expressions, branching, pattern matching, and loops to model program flow.
Conditions and if expressions
In Rust, if is an expression and branches that return a value must have compatible types.
Match and pattern matching
match checks a value against patterns and requires exhaustive handling.
Loop, while, for, and ranges
Rust offers loop, while, and for for different repetition patterns.
Module checkpoint: Write a temperature classifier with if, a status classifier with match, and a loop that prints the values 1 through 5. Explain the endpoint of each range.
4. Functions, closures, and control-flow results
BeginnerWrite reusable functions, understand return values, and learn the foundations of closures and early exits.
Functions and parameters
A function signature describes its inputs and output type.
Return values, tuples, and early return
Functions can return tuples and use return for an explicit early exit.
Closures and captured values
Closures are anonymous functions that can capture values from their surrounding scope.
Module checkpoint: Create a function that returns a useful result, one that reports absence with Option, and a closure used to transform a list of numbers.
5. Ownership, borrowing, and slices
IntermediateUnderstand Rust's ownership model, borrow references safely, and work with slices without unnecessary copying.
Ownership and moves
Each owned value has an owner, and ownership moves can transfer responsibility without copying the data.
References and borrowing
References let functions access a value without taking ownership of it.
Slices and borrowing rules
Slices borrow a contiguous part of a collection without owning it.
Module checkpoint: Write a function that accepts a string slice and returns its length, then write a function that borrows an integer slice and computes its sum. Identify who owns each input.
6. Structs, enums, and pattern matching
IntermediateModel domain data with structs and enums, then use pattern matching to handle variants explicitly.
Structs and methods
Structs group named fields into a type that represents one concept.
Enums and Option
Enums represent a value that can be one of several named variants.
Match, if let, and destructuring
Patterns extract data from enum variants, tuples, and structs.
Module checkpoint: Model a task with a struct and an enum status. Write a method to update it and handle an Option value using match or if let.
7. Collections, strings, and iterators
IntermediateStore dynamic collections, work safely with UTF-8 strings, and transform data with iterators.
Vectors and dynamic sequences
Vec<T> stores a growable sequence of values of one type.
String, &str, and HashMap
String owns growable UTF-8 text, &str borrows text, and HashMap stores key-value pairs.
Iterators and transformations
Iterators express sequences of values and can be composed into clear data transformations.
Module checkpoint: Build a small collection of scores, calculate the average using iteration, store per-student totals in a HashMap, and handle missing keys without assuming they exist.
8. Option, Result, and error handling
IntermediateMake absence and failures explicit, propagate errors with ?, and choose between recoverable errors and panics.
Handling optional values
Option represents a value that may or may not be present.
Result and the question-mark operator
Result<T, E> represents success or failure, and ? propagates compatible errors.
Panics, validation, and error context
Use Result for expected failures and reserve panics for broken assumptions or unrecoverable situations.
Module checkpoint: Write a function that parses an integer from text and returns Result. Handle a missing collection element with Option, and describe which errors should be shown to a user rather than panic.
9. Generics, traits, and lifetimes
AdvancedReuse behavior with generics and traits, understand trait bounds, and read lifetime annotations in borrowed data APIs.
Generic functions and types
Generics let code work with multiple types while retaining compile-time type checking.
Traits and trait bounds
Traits describe behavior that types can implement, while bounds specify the behavior a generic type must provide.
Reading lifetime annotations
Lifetime annotations describe relationships between references rather than extending data's lifetime.
Module checkpoint: Implement a generic function with a trait bound, define a small trait for a domain type, and read a borrowed return type with an explicit lifetime. Explain what each bound guarantees.
10. Modules, Cargo, and testing
IntermediateOrganize code into modules and crates, manage dependencies, and create reliable automated tests.
Modules, paths, and visibility
Modules organize code and Rust privacy controls which items can be accessed from outside a module.
Cargo dependencies and reproducible builds
Cargo resolves dependencies and records project configuration and versions.
Unit tests and integration tests
Rust supports unit tests in source modules and integration tests under the tests directory.
Module checkpoint: Split a small application into two modules, make only the necessary items public, add unit tests for normal and boundary cases, and run cargo fmt, cargo test, and cargo clippy.
11. Smart pointers and interior mutability
AdvancedLearn when ownership wrappers such as Box, Rc, Arc, Cell, and RefCell are useful, and understand their tradeoffs.
Box and heap allocation
Box<T> owns a value allocated on the heap and gives it a stable indirection in the type structure.
Shared ownership with Rc and Arc
Rc and Arc allow multiple owners to share a value, with different concurrency guarantees.
Cell, RefCell, and Mutex
Interior mutability permits mutation through a shared outer reference using specific runtime or synchronization rules.
Module checkpoint: Model a recursive data structure with Box and compare it with a shared-ownership example. Explain why Rc, Arc, RefCell, and Mutex solve different problems.
12. Threads, channels, and asynchronous concepts
AdvancedCoordinate concurrent work using threads, message passing, and shared state, while understanding where async runtimes fit.
Threads and join handles
Rust threads can execute work concurrently while ownership rules constrain what data crosses thread boundaries.
Channels and synchronized state
Channels send values between concurrent tasks, while mutexes protect shared mutable state.
Async functions and futures
async functions describe work that can be polled to completion by an executor.
Module checkpoint: Create two worker threads and coordinate their results. Then compare message passing with a shared Mutex-protected counter, documenting how errors and shutdown are handled.
13. Files, command-line apps, performance, and unsafe boundaries
AdvancedBuild practical Rust command-line programs, process files safely, measure performance, and understand the limits of unsafe code.
Reading and writing files
File operations return Results because permissions, paths, and storage can cause failures.
Command-line arguments and application layers
A reliable CLI separates argument parsing, domain operations, and presentation.
Performance, profiling, and unsafe code
Measure performance before optimizing, and treat unsafe blocks as explicit proof obligations.
Module checkpoint: Build a CLI tool that reads a text file, validates a command, summarizes the content, and writes a report. Test I/O errors and invalid arguments, then profile only if you have evidence of a performance problem.