Rust
Rust from absolute zero to advanced: what a compiler does, values and types and how they sit in memory, then the ideas that make Rust different (ownership, borrowing, lifetimes) taught slowly with diagrams and real compiler errors. After that: structs, enums and pattern matching, error handling, collections, generics and traits, closures and iterators, modules and testing, smart pointers, threads, a look at unsafe code and FFI, and two practical projects. Exercises are compiled with rustc and checked in a sandbox; reading the compiler's messages is part of the craft, so some exercises start out broken on purpose.
- Getting Started: Programs and the Compiler
What a program is, what rustc does to your source, cargo, reading compiler errors, and printing formatted output.- What a Program Is, and What a Compiler Does · 30 min · 5 exercises
- rustc and cargo · 30 min · 4 exercises
- Reading Compiler Errors · 30 min · 5 exercises
- Printing and Formatting Output · 35 min · 5 exercises
- Variables, Types and Functions
Bindings, mutability and shadowing; integer, float, bool and char types and their bits; tuples and arrays in memory; functions, expressions and statements; reading input.- Variables, Mutability and Shadowing · 35 min · 5 exercises
- Integers: Bits, Sizes and Overflow · 40 min · 5 exercises
- Floats, Booleans, Characters and Casts · 40 min · 5 exercises
- Tuples and Arrays in Memory · 40 min · 5 exercises
- Functions, Expressions and Statements · 40 min · 5 exercises
- Reading Input: stdin and Command-Line Arguments · 40 min · 5 exercises
- Control Flow
if as an expression, loop, while and for, ranges, labeled breaks, and a first look at match.- if, else and Conditions as Expressions · 35 min · 4 exercises
- Loops: loop, while, break and continue · 40 min · 4 exercises
- for Loops, Ranges and Iterating Arrays · 40 min · 4 exercises
- First match: Choosing Between Many Cases · 35 min · 4 exercises
- Practice: Small Programs with Loops · 50 min · 4 exercises
- Ownership
The stack and the heap, ownership and moves, Copy and Clone, Drop and scope, and how ownership flows through functions.- The Stack and the Heap · 40 min · 4 exercises
- Ownership Rules and Moves · 45 min · 4 exercises
- Copy, Clone and the Cost of Duplicating · 35 min · 4 exercises
- Scope and Drop: Deterministic Cleanup · 40 min · 4 exercises
- Ownership Through Functions · 40 min · 4 exercises
- Borrowing and Slices
Shared and mutable references, the aliasing rule, how the borrow checker reasons, dangling references, and slices.- References: Borrowing Without Taking · 40 min · 4 exercises
- Mutable References and the Aliasing Rule · 40 min · 4 exercises
- Inside the Borrow Checker · 40 min · 4 exercises
- Dangling References and Why Rust Forbids Them · 35 min · 3 exercises
- Slices: Borrowing Part of a Collection · 40 min · 4 exercises
- Strings and Text
String versus &str, UTF-8 bytes and chars, why you cannot index a string, and practical text processing.- String and &str · 35 min · 3 exercises
- UTF-8: Bytes, chars and Why s[0] Does Not Compile · 40 min · 4 exercises
- Working with Text: Splitting, Trimming, Parsing, Building · 45 min · 3 exercises
- Structs, Enums and Pattern Matching
Defining your own types, methods and associated functions, enums that carry data, and match, if let and destructuring in depth.- Structs: Grouping Data · 40 min · 4 exercises
- Methods and impl Blocks · 40 min · 3 exercises
- Enums: Types with Variants · 45 min · 4 exercises
- Pattern Matching in Depth · 45 min · 4 exercises
- Option, Result and Error Handling
Absence without null, recoverable versus unrecoverable errors, the ? operator, and writing your own error types.- Option: A Value That Might Not Be There · 40 min · 3 exercises
- Result and panic!: Recoverable and Unrecoverable Errors · 45 min · 3 exercises
- The ? Operator and Propagating Errors · 40 min · 3 exercises
- Custom Error Types · 45 min · 3 exercises
- Collections
Vec in depth with its memory layout, HashMap and BTreeMap with the entry API, sets, and choosing the right collection.- Vec in Depth · 40 min · 3 exercises
- HashMap and BTreeMap · 45 min · 3 exercises
- Sets, VecDeque and Choosing a Collection · 45 min · 4 exercises
- Generics, Traits and Lifetimes
Generic functions and types, defining and implementing traits, static versus dynamic dispatch, the standard traits, and lifetimes.- Generics: Code for Many Types · 40 min · 3 exercises
- Traits: Shared Behavior · 45 min · 3 exercises
- Trait Bounds, impl Trait and dyn Trait · 45 min · 3 exercises
- The Standard Traits and derive · 40 min · 3 exercises
- Lifetimes: Naming How Long Borrows Live · 45 min · 3 exercises
- Closures and Iterators
Closures and what they capture, Fn, FnMut and FnOnce, the Iterator trait, adapters and laziness, and writing your own iterators.- Closures and Capturing · 40 min · 3 exercises
- Fn, FnMut and FnOnce · 35 min · 3 exercises
- The Iterator Trait and Adapters · 45 min · 3 exercises
- Writing Your Own Iterator · 40 min · 3 exercises
- Modules, Visibility and Testing
Organizing code with mod and pub, paths and use, how files map to modules in a cargo project, and unit tests with #[test].- Modules, Visibility and Paths · 45 min · 3 exercises
- Unit Tests with #[test] · 45 min · 3 exercises
- Testing Well: Edge Cases, Panics and Test Design · 45 min · 3 exercises
- Smart Pointers
Box for heap allocation and recursive types, Deref and Drop, Rc for shared ownership, RefCell for interior mutability, and Weak to break cycles.- Box, Deref and Drop: Owning Data on the Heap · 45 min · 3 exercises
- Rc: Shared Ownership · 35 min · 3 exercises
- RefCell and Interior Mutability · 40 min · 3 exercises
- Weak References and Reference Cycles · 40 min · 3 exercises
- Concurrency
Threads and join, moving data into threads, channels, Arc and Mutex, Send and Sync, and scoped threads.- Threads: Running Code at the Same Time · 40 min · 3 exercises
- Channels: Passing Messages Between Threads · 40 min · 3 exercises
- Shared State: Arc and Mutex · 45 min · 3 exercises
- Send, Sync and Scoped Threads · 40 min · 3 exercises
- Unsafe Rust and FFI
What unsafe permits and what it still checks, raw pointers, writing safe abstractions over unsafe code, and calling C from Rust.- What unsafe Means, and Raw Pointers · 45 min · 3 exercises
- Safe Abstractions over Unsafe Code · 40 min · 3 exercises
- FFI: Calling C from Rust, and Rust from C · 50 min · 3 exercises
- Projects
Putting it together: a command-line word-frequency tool with options, a CSV state machine, and an expression interpreter with a tokenizer and recursive-descent parser.- Project: A Word-Frequency Tool with Options · 60 min · 2 exercises
- Project: A State Machine for CSV · 60 min · 2 exercises
- Project: An Expression Interpreter · 90 min · 2 exercises