Skip to content

Rust Programming Textbook

A free, self-paced textbook in 8 chapters. Read a chapter, then drill it with the 50 companion flashcards using spaced repetition.

8 chapters · 50 cards · Updated

Chapters

  1. 1Foundations of Rust Memory Safety

    Rust is a systems programming language that targets three goals at once: safety, speed, and concurrency. What distinguishes it from most peers is that it achieves memory safety wit...

  2. 2Structures, Enums, and Pattern Matching

    Rust offers two principal ways to compose custom data types: structs and enums. A struct groups related fields together, and Rust supports three flavors — named-field structs, tupl...

  3. 3Error Handling with Option and Result

    Rust replaces the concept of `null` with the `Option` enum, which has two variants: `Some(T)` when a value is present and `None` when it is absent. Because `Option` is just an enum...

  4. 4Traits, Generics, and Polymorphism

    Traits are Rust's mechanism for describing shared behavior. A trait declares a set of methods that a type must implement, much like an interface in object-oriented languages, and a...

  5. 5Iterators, Closures, and Functional Patterns

    Iterators are the foundation of Rust's approach to sequences. Any type that implements the `Iterator` trait must provide a `next()` method returning `Option`: `Some(item)` while el...

  6. 6Modules, Crates, Cargo, and Testing

    Rust organizes code using modules, declared with the `mod` keyword. A module is a namespace that can hold functions, structs, enums, constants, and other modules. Items inside a mo...

  7. 7Concurrency in Rust

    Rust's concurrency story begins with `std::thread::spawn`, which takes a closure and returns a `JoinHandle`. Calling `.join().unwrap()` on the handle blocks the current thread unti...

  8. 8Smart Pointers and Unsafe Rust

    Beyond plain references, Rust offers smart pointers that own or manage data in more sophisticated ways. `Box` allocates a value on the heap and owns the only pointer to it. It is e...

← Back to the Rust Programming deck