---
title: "Learn Rust"
description: "Free Rust tutorials. Learn Rust from scratch, one lesson at a time."
url: "https://learnrust.net/"
last_updated: "2026-06-13"
---

# Learn Rust

> Free Rust tutorials. Learn Rust from scratch, one lesson at a time.

Free, beginner-first tutorials for the Rust programming language, organized as a sequential course. No prior programming experience is assumed: 216 lessons across 30 chapters, each with a markdown copy at the same URL with `.md` appended.

An MCP server for searching and reading the course is at https://learnrust.net/mcp (Streamable HTTP, no authentication).

## Chapter 0: Introduction / Getting Started

- [0.1 Introduction to these tutorials](https://learnrust.net/chapter-0/introduction-to-these-tutorials.md): What this free Rust course covers, how it's organized, and how to get the most out of every lesson.
- [0.2 Introduction to programs and languages](https://learnrust.net/chapter-0/introduction-to-programs-and-languages.md): What a program is, machine code, assembly, and high-level languages: where Rust fits in the world of programming.
- [0.3 Introduction to Rust](https://learnrust.net/chapter-0/introduction-to-rust.md): A short history of the Rust programming language, what makes it different, and answers to the questions every beginner asks.
- [0.4 Introduction to Rust development](https://learnrust.net/chapter-0/introduction-to-rust-development.md): The seven steps of developing a program, why design is the neglected one, and the true story of the first computer bug.
- [0.5 The compiler, Cargo, and crates](https://learnrust.net/chapter-0/the-compiler-cargo-and-crates.md): What the Rust compiler does, what Cargo is for, and what crates and the standard library are.
- [0.6 Installing Rust](https://learnrust.net/chapter-0/installing-rust.md): Installing Rust with rustup on Windows, macOS, and Linux, including the Build Tools prerequisite, verification, and updating.
- [0.7 Setting up a code editor](https://learnrust.net/chapter-0/setting-up-a-code-editor.md): Choosing and installing a Rust code editor: VS Code with rust-analyzer, RustRover, and the setups to avoid.
- [0.8 Compiling your first program](https://learnrust.net/chapter-0/compiling-your-first-program.md): Create your first Rust project with cargo new, run it with cargo run, and meet Cargo.toml, main.rs, and the target folder.
- [0.9 A few common problems](https://learnrust.net/chapter-0/a-few-common-problems.md): Fixes for the most common Rust setup problems: command not found, linker errors, antivirus quarantines, and more.
- [0.10 Build configurations: debug and release](https://learnrust.net/chapter-0/build-configurations.md): Rust's dev and release build profiles: what each is for, how much speed release buys, and which to use when.
- [0.11 Warnings, lints, and Clippy](https://learnrust.net/chapter-0/warnings-lints-and-clippy.md): Rust compiler warnings, why they're on by default, the underscore convention, and the Clippy and rustfmt tools.
- [0.12 Rust editions](https://learnrust.net/chapter-0/rust-editions.md): What Rust editions are (2015, 2018, 2021, 2024), why they exist, and why you barely need to think about them.

## Chapter 1: Rust Basics

- [1.1 Statements and the structure of a program](https://learnrust.net/chapter-1/statements-and-program-structure.md): What statements are, why every Rust program starts at fn main, and a line-by-line dissection of Hello, world.
- [1.2 Comments](https://learnrust.net/chapter-1/comments.md): Rust comments: // and /* */ syntax, what to comment and why, and commenting out code.
- [1.3 Introduction to values and variables](https://learnrust.net/chapter-1/values-and-variables.md): Data, values, RAM, and Rust variables: what let does, and how the compiler tracks every variable's type.
- [1.4 Variables, mutability, and initialization](https://learnrust.net/chapter-1/variables-mutability-initialization.md): Why Rust variables are immutable by default, what let mut does, and how the compiler makes uninitialized reads impossible.
- [1.5 Introduction to println! and formatting](https://learnrust.net/chapter-1/println-and-formatting.md): Printing in Rust: println! versus print!, placeholder syntax, named and positional arguments, and escape sequences.
- [1.6 Reading input: a first look](https://learnrust.net/chapter-1/reading-input.md): Reading user input in Rust with stdin and read_line, why the input keeps its newline, and what trim does.
- [1.7 Compiler errors and how to read them](https://learnrust.net/chapter-1/reading-compiler-errors.md): The anatomy of a Rust compiler error: error codes, spans, labels, help lines, and the habit of reading the first error first.
- [1.8 Keywords and naming identifiers](https://learnrust.net/chapter-1/keywords-and-identifiers.md): Rust's reserved keywords, the rules for identifiers, and the snake_case naming conventions the compiler itself nudges you toward.
- [1.9 Whitespace and basic formatting](https://learnrust.net/chapter-1/whitespace-and-formatting.md): How Rust treats whitespace, the standard 4-space style, and how cargo fmt ended the formatting wars.
- [1.10 Introduction to literals and operators](https://learnrust.net/chapter-1/literals-and-operators.md): Literals, operands, and operators in Rust, including why the ++ and -- operators don't exist.
- [1.11 Expressions and statements](https://learnrust.net/chapter-1/expressions-and-statements.md): Rust is an expression-oriented language: blocks produce values, semicolons discard them, and the unit type fills the gaps.
- [1.12 Developing your first program](https://learnrust.net/chapter-1/developing-your-first-program.md): Build a complete small Rust program step by step, hit a real compiler error, fix it, and compare three working solutions.
- [1.x Chapter 1 summary and quiz](https://learnrust.net/chapter-1/chapter-1-summary-and-quiz.md): Every term from Chapter 1 in one place, plus a quiz that ends with writing a complete program.

## Chapter 2: Functions

- [2.1 Introduction to functions](https://learnrust.net/chapter-2/introduction-to-functions.md): Defining and calling Rust functions, tracing the flow of control, and why definition order doesn't matter.
- [2.2 Function return values](https://learnrust.net/chapter-2/return-values.md): Rust return types, tail expressions as return values, the return keyword, and the missing-semicolon error every beginner meets.
- [2.3 Function parameters and arguments](https://learnrust.net/chapter-2/parameters-and-arguments.md): Parameters versus arguments in Rust, why every parameter is explicitly typed, and how values are copied into calls.
- [2.4 Local scope and blocks](https://learnrust.net/chapter-2/local-scope-and-blocks.md): Where Rust variables live and die: scope, blocks, shadowing across functions, and defining variables near first use.
- [2.5 Why functions are useful](https://learnrust.net/chapter-2/why-functions-are-useful.md): The five things functions buy you, when to split code into one, and the read-compute-print pattern.
- [2.6 How to design your first programs](https://learnrust.net/chapter-2/designing-your-first-programs.md): Turning a problem into a program: goals, requirements, top-down decomposition, and building one tested function at a time.
- [2.x Chapter 2 summary and quiz](https://learnrust.net/chapter-2/chapter-2-summary-and-quiz.md): Chapter 2's terms in review, plus the classic three-function program quiz.

## Chapter 3: Debugging Rust Programs

- [3.1 Syntax and semantic errors](https://learnrust.net/chapter-3/syntax-and-semantic-errors.md): The two kinds of programming errors, which ones Rust's compiler catches, and which ones survive to runtime.
- [3.2 The debugging process](https://learnrust.net/chapter-3/the-debugging-process.md): A six-step process for finding and fixing bugs, applied to a real broken program.
- [3.3 A strategy for debugging](https://learnrust.net/chapter-3/a-strategy-for-debugging.md): Narrowing down where a bug lives: code inspection, reproduction, and binary-searching the pipeline.
- [3.4 Print debugging: eprintln! and dbg!](https://learnrust.net/chapter-3/print-debugging.md): Debugging with output: stderr versus stdout, the dbg! macro's file-and-line reports, and a worked bug hunt.
- [3.5 Using a debugger: breakpoints and stepping](https://learnrust.net/chapter-3/using-a-debugger.md): Pausing a live Rust program with a debugger: breakpoints, stepping, watching variables, and the call stack, in VS Code and elsewhere.
- [3.6 Finding issues before they become problems](https://learnrust.net/chapter-3/finding-issues-early.md): Habits that prevent bugs: small functions, incremental builds, defensive thinking, Clippy, and a taste of automated tests.
- [3.x Chapter 3 summary and quiz](https://learnrust.net/chapter-3/chapter-3-summary-and-quiz.md): Debugging terms in review, plus a quiz of real broken programs to hunt through.

## Chapter 4: Fundamental Data Types

- [4.1 Introduction to fundamental data types](https://learnrust.net/chapter-4/introduction-to-fundamental-data-types.md): Bits, bytes, and what a type actually is: how Rust decides what the bits in memory mean.
- [4.2 Integer types](https://learnrust.net/chapter-4/integer-types.md): Rust's ten integer types, their exact ranges, signed versus unsigned, and why mixing them is a compile error rather than a bug.
- [4.3 isize, usize, and integer literals](https://learnrust.net/chapter-4/isize-usize-and-integer-literals.md): Rust's pointer-sized integers, where usize shows up, and the full integer literal syntax: suffixes, underscores, hex, octal, and binary.
- [4.4 Integer overflow](https://learnrust.net/chapter-4/integer-overflow.md): What happens when Rust arithmetic exceeds a type's range: debug panics, release wrapping, and the checked, wrapping, and saturating alternatives.
- [4.5 Floating-point types](https://learnrust.net/chapter-4/floating-point-types.md): Rust's f32 and f64: scientific notation, precision limits, rounding error, infinity, and NaN.
- [4.6 Boolean values](https://learnrust.net/chapter-4/boolean-values.md): Rust's bool type: true, false, the ! operator, and why there's no truthiness.
- [4.7 Introduction to if expressions](https://learnrust.net/chapter-4/introduction-to-if-expressions.md): Rust's if: bool-only conditions, mandatory braces, else chains, and the twist that if produces a value.
- [4.8 char and a first look at Unicode](https://learnrust.net/chapter-4/char-and-unicode.md): Rust's char type: four bytes, Unicode scalar values, single versus double quotes, and why '5' is not 5.
- [4.9 Type inference and annotations](https://learnrust.net/chapter-4/type-inference-and-annotations.md): How Rust infers types from values and usage, the i32 and f64 defaults, and the rare cases where it needs your help.
- [4.10 Numeric conversions with as](https://learnrust.net/chapter-4/numeric-conversions.md): Explicit casts in Rust: widening, truncation, float-to-int saturation, and why every conversion is your signature on a form.
- [4.11 Tuples and the unit type](https://learnrust.net/chapter-4/tuples-and-the-unit-type.md): Grouping values with tuples, destructuring, returning multiple values from functions, and the truth about ().
- [4.x Chapter 4 summary and quiz](https://learnrust.net/chapter-4/chapter-4-summary-and-quiz.md): Every type and term from Chapter 4, plus a calculator program and the famous falling-ball exercise.

## Chapter 5: Constants, Shadowing, and Strings

- [5.1 Constants and statics](https://learnrust.net/chapter-5/constants-and-statics.md): Declaring compile-time constants with const, naming them, hunting magic numbers, and the two paragraphs static deserves.
- [5.2 Shadowing](https://learnrust.net/chapter-5/shadowing.md): Rebinding a name with let, why shadowing isn't mutation, and the type-changing idiom Rust programmers use everywhere.
- [5.3 Introduction to String](https://learnrust.net/chapter-5/introduction-to-string.md): Rust's owned, growable text type: creating Strings, growing them with push_str, and what len() really counts.
- [5.4 Introduction to &str](https://learnrust.net/chapter-5/introduction-to-str.md): String literals unmasked: the borrowed string type, why trim never copies, and how to choose function parameter types.
- [5.5 Formatting strings](https://learnrust.net/chapter-5/formatting-strings.md): format! and the formatting mini-language: width, alignment, precision, zero-padding, and the {:?} debug view.
- [5.6 Parsing strings into numbers](https://learnrust.net/chapter-5/parsing-strings-into-numbers.md): The read-a-number incantation taken apart: trim, parse, the turbofish, and what happens when the user types potato.
- [5.x Chapter 5 summary and quiz](https://learnrust.net/chapter-5/chapter-5-summary-and-quiz.md): Constants, shadowing, String and &str, formatting and parsing reviewed, plus a quiz that uses the whole chapter at once.

## Chapter 6: Operators

- [6.1 Operator precedence and associativity](https://learnrust.net/chapter-6/operator-precedence-and-associativity.md): How Rust decides which operators apply first, why chained comparisons refuse to compile, and the one rule worth memorizing.
- [6.2 Arithmetic operators](https://learnrust.net/chapter-6/arithmetic-operators.md): Integer vs float division, the remainder operator, division by zero, and how Rust does exponents without an exponent operator.
- [6.3 Compound assignment: the missing ++](https://learnrust.net/chapter-6/compound-assignment.md): The += family of operators, and what Rust's deliberate lack of an increment operator says about the language's taste.
- [6.4 Comparison operators and float equality](https://learnrust.net/chapter-6/comparison-operators-and-float-equality.md): The six comparison operators in full, why == betrays floating-point values, and the epsilon technique professionals use instead.
- [6.5 Logical operators](https://learnrust.net/chapter-6/logical-operators.md): AND, OR, short-circuit evaluation, De Morgan's laws, and the classic mistake that Rust turns into a type error.
- [6.6 Bitwise operators (optional)](https://learnrust.net/chapter-6/bitwise-operators.md): AND, OR, XOR, NOT, and shifts on raw bits, plus the bit-flag idioms used in graphics, embedded, and systems code.
- [6.x Chapter 6 summary and quiz](https://learnrust.net/chapter-6/chapter-6-summary-and-quiz.md): Precedence, arithmetic, comparisons, and logic reviewed, plus a change-counting program that needs the whole chapter.

## Chapter 7: Control Flow

- [7.1 Control flow introduction](https://learnrust.net/chapter-7/control-flow-introduction.md): Execution paths, branching, and a map of Rust's control flow tools: if, match, loops, jumps, and halts.
- [7.2 Working with if and else](https://learnrust.net/chapter-7/working-with-if-and-else.md): if-else chains versus separate ifs, flattening nested conditions, early returns, and the scope of values born inside an arm.
- [7.3 Introduction to match](https://learnrust.net/chapter-7/introduction-to-match.md): Rust's match expression: arms, patterns, the _ wildcard, or-patterns, and exhaustiveness checking as a feature.
- [7.4 loop and while](https://learnrust.net/chapter-7/loop-and-while.md): Rust's while loop, the dedicated loop keyword for infinite loops, the do-while idiom, and the unsigned countdown trap.
- [7.5 for loops and ranges](https://learnrust.net/chapter-7/for-loops-and-ranges.md): Rust's for loop over ranges: half-open and inclusive ranges, rev and step_by, and why there's no three-part C-style for.
- [7.6 break, continue, and loop labels](https://learnrust.net/chapter-7/break-continue-and-loop-labels.md): Ending loops early, skipping iterations, break-with-value from loop, and labeled breaks for nested loops.
- [7.7 Introduction to recursion](https://learnrust.net/chapter-7/introduction-to-recursion.md): Functions that call themselves: base cases, recursive cases, stack overflows, and when to prefer a loop.
- [7.8 Halting your program early](https://learnrust.net/chapter-7/halting-your-program-early.md): Exit codes, returning from main, std::process::exit, and a first proper introduction to panic!.
- [7.9 Adding a dependency: random numbers](https://learnrust.net/chapter-7/adding-a-dependency-random-numbers.md): PRNGs and seeds, crates.io, cargo add, semantic versioning, and rolling dice with the rand crate.
- [7.10 Project: the number guessing game](https://learnrust.net/chapter-7/project-number-guessing-game.md): Build the classic guessing game in Rust: loops, match on Ordering, input parsing, and your first complete program.
- [7.x Chapter 7 summary and quiz](https://learnrust.net/chapter-7/chapter-7-summary-and-quiz.md): Control flow reviewed: match, the three loops, jumps, recursion, halts, and dependencies, plus a quiz that builds real programs.

## Chapter 8: Ownership and Moves

- [8.1 Introduction to ownership](https://learnrust.net/chapter-8/introduction-to-ownership.md): Why memory management is the problem every language must solve, and how Rust's compile-time ownership rules differ from manual management and garbage collection.
- [8.2 The stack and the heap](https://learnrust.net/chapter-8/the-stack-and-the-heap.md): Where Rust programs keep their values: stack frames and why they're fast, the heap and why it needs cleanup, and what a String really looks like in memory.
- [8.3 Scope and drop](https://learnrust.net/chapter-8/scope-and-drop.md): Rust frees a value the moment its owner goes out of scope: what 'dropped' means, and why deterministic cleanup beats waiting for a garbage collector.
- [8.4 Moves: assignment transfers ownership](https://learnrust.net/chapter-8/moves.md): What let s2 = s1 really does to a String: why Rust moves ownership instead of copying, and the use-after-move error message read line by line.
- [8.5 Copy types: when assignment copies](https://learnrust.net/chapter-8/copy-types.md): Why integers never triggered a move error: the Copy marker, which Rust types copy on assignment versus move, and how to tell at a glance.
- [8.6 Ownership and functions](https://learnrust.net/chapter-8/ownership-and-functions.md): Passing a String to a function moves it, returning gives ownership back: the full story behind 'arguments are copied', and why chapter 9 exists.
- [8.7 Clone: explicit deep copies](https://learnrust.net/chapter-8/clone.md): When you genuinely need two copies of a String, .clone() duplicates the heap data: how it works, what it costs, and when reaching for it is a mistake.
- [8.x Chapter 8 summary and quiz](https://learnrust.net/chapter-8/chapter-8-summary-and-quiz.md): Ownership, the stack and heap, drops, moves, Copy and Clone reviewed, plus a quiz that exercises the whole ownership model at once.

## Chapter 9: References and Borrowing

- [9.1 References: borrowing a value](https://learnrust.net/chapter-9/references-borrowing-a-value.md): Rust references let functions use a value without taking ownership: the & operator, borrowing, and why references are immutable by default.
- [9.2 Mutable references](https://learnrust.net/chapter-9/mutable-references.md): The &mut reference lets a function modify a borrowed value, under Rust's one-writer-or-many-readers rule, enforced by the borrow checker.
- [9.3 The borrow checker is your friend](https://learnrust.net/chapter-9/the-borrow-checker-is-your-friend.md): The four borrow checker errors every new Rust programmer hits in week one: E0596, E0502, E0382, and E0506, each read line by line and fixed.
- [9.4 References and functions](https://learnrust.net/chapter-9/references-and-functions.md): How to choose function parameter types in Rust: by value for Copy types, &T to read, &mut T to modify in place, and owned types to keep.
- [9.5 Dangling references](https://learnrust.net/chapter-9/dangling-references.md): What dangling references are, how C++ lets them happen, and how Rust's compiler refuses to let a reference outlive the value it points to.
- [9.6 Slices](https://learnrust.net/chapter-9/slices.md): Rust slices explained: borrowing a view of part of a sequence with range syntax, the &[T] type, and why functions take slices instead of arrays.
- [9.7 String slices](https://learnrust.net/chapter-9/string-slices.md): &str fully explained at last: string slices, range syntax on text, why parameters take &str over &String, and deref coercion.
- [9.x Chapter 9 summary and quiz](https://learnrust.net/chapter-9/chapter-9-summary-and-quiz.md): Review of references, borrowing, the borrow checker, dangling references, and slices, with a chapter quiz and a capstone program.

## Chapter 10: Structs and Methods

- [10.1 Introduction to program-defined types](https://learnrust.net/chapter-10/introduction-to-program-defined-types.md): Why every language lets you define your own types, how a struct groups related data under one name, and Rust's naming conventions for types.
- [10.2 Defining and instantiating structs](https://learnrust.net/chapter-10/defining-and-instantiating-structs.md): How to define a struct's fields, create an instance, read and write fields with dot notation, and why Rust makes the whole struct mutable, not individual fields.
- [10.3 Field init shorthand and update syntax](https://learnrust.net/chapter-10/field-init-and-update-syntax.md): Field init shorthand removes repetition when a variable already shares a field's name, and struct update syntax builds a new instance from an existing one.
- [10.4 Tuple structs and unit structs](https://learnrust.net/chapter-10/tuple-structs-and-unit-structs.md): Tuple structs give a tuple a name and its own type, the newtype pattern wraps a value to make it distinct, and unit structs carry no data at all.
- [10.5 Methods and impl blocks](https://learnrust.net/chapter-10/methods-and-impl-blocks.md): How impl blocks attach methods to a struct, the difference between &self, &mut self, and self, and why method receivers are just chapters 8 and 9 in new clothing.
- [10.6 Associated functions and constructors](https://learnrust.net/chapter-10/associated-functions-and-constructors.md): Associated functions belong to a type without taking self; ::new is a convention not a keyword, and Default supplies sensible starting values.
- [10.7 Deriving Debug and printing structs](https://learnrust.net/chapter-10/deriving-debug.md): Why a struct can't be printed with {} by default, how #[derive(Debug)] enables {:?} and {:#?}, and what derive means as boilerplate the compiler writes.
- [10.8 Ownership in structs](https://learnrust.net/chapter-10/ownership-in-structs.md): Structs own their fields, so moving a struct moves everything inside it; storing a reference in a struct requires a lifetime, which Rust defers to chapter 17.
- [10.9 Project: rectangles](https://learnrust.net/chapter-10/project-rectangles.md): A program built one compiling step at a time: from loose variables to a tuple to a struct with methods, watching each refactor make the code clearer.
- [10.x Chapter 10 summary and quiz](https://learnrust.net/chapter-10/chapter-10-summary-and-quiz.md): Review of structs, methods, associated functions, deriving Debug, and ownership in structs, with a chapter quiz and a capstone program.

## Chapter 11: Enums and Pattern Matching

- [11.1 Enums](https://learnrust.net/chapter-11/enums.md): An enum is a type whose value is exactly one of a fixed set of named variants; when an enum beats a bool, and why match pairs so naturally with enums.
- [11.2 Enums with data](https://learnrust.net/chapter-11/enums-with-data.md): Rust enum variants can carry values of their own, making an enum a value that is one of several shapes; the lightbulb feature that makes enums a headline of the language.
- [11.3 Option and the end of null](https://learnrust.net/chapter-11/option.md): Option<T> is Rust's answer to the billion-dollar null mistake: absence is a value the compiler forces you to handle, and unwrap/expect are finally explained in full.
- [11.4 match in depth](https://learnrust.net/chapter-11/match-in-depth.md): The full power of match: binding patterns, multiple patterns, ranges, match guards, and the @ binding operator, plus the catch-all patterns _ and a name.
- [11.5 Destructuring](https://learnrust.net/chapter-11/destructuring.md): Patterns aren't only for match: destructuring pulls apart structs, tuples, and enums, including in let bindings and function parameters, with nesting.
- [11.6 if let, while let, and let else](https://learnrust.net/chapter-11/if-let-while-let-let-else.md): Three lighter alternatives to match for when you only care about one pattern: if let for a single case, while let for looping, and let else for early exit.
- [11.7 Methods on enums](https://learnrust.net/chapter-11/methods-on-enums.md): impl works on enums just like structs; the worked example is a state machine, where each method matches on self to decide behavior per variant.
- [11.x Chapter 11 summary and quiz](https://learnrust.net/chapter-11/chapter-11-summary-and-quiz.md): Review of enums, data-carrying variants, Option, match in depth, destructuring, the if let family, and enum methods, with a chapter quiz and capstone.

## Chapter 12: Error Handling

- [12.1 panic! and unrecoverable errors](https://learnrust.net/chapter-12/panic-and-unrecoverable-errors.md): What panicking actually does, reading a backtrace with RUST_BACKTRACE, and assert!/debug_assert! as the panic machinery behind checked assumptions.
- [12.2 Result and recoverable errors](https://learnrust.net/chapter-12/result.md): Result<T, E> is the enum for operations that can fail; match on it, and understand unwrap and expect as deliberate convert-to-panic choices.
- [12.3 Propagating errors: the ? operator](https://learnrust.net/chapter-12/propagating-errors-question-mark-operator.md): The ? operator turns pages of match-on-Result boilerplate into one character: it returns the error early on Err and unwraps the value on Ok.
- [12.4 Handling invalid input properly](https://learnrust.net/chapter-12/handling-invalid-input.md): Turning the guessing game's expect crash into a polite retry loop, and a taxonomy of the ways user input goes wrong: malformed, out of range, and absent.
- [12.5 When to panic and when to return Result](https://learnrust.net/chapter-12/when-to-panic.md): Guidelines for choosing between panic and Result: expected versus exceptional, contracts, library versus application code, and when unwrap is fine.
- [12.6 Custom error types: a first look](https://learnrust.net/chapter-12/custom-error-types.md): Building error types as enums so callers can inspect what went wrong, implementing Display, and the Box<dyn Error> escape hatch for when you just want errors to flow.
- [12.x Chapter 12 summary and quiz](https://learnrust.net/chapter-12/chapter-12-summary-and-quiz.md): Review of panic, Result, the ? operator, handling invalid input, when to panic, and custom error types, with a chapter quiz and a capstone program.

## Chapter 13: Modules, Crates, and Cargo

- [13.1 Naming collisions, and why modules exist](https://learnrust.net/chapter-13/naming-collisions-and-modules.md): As programs grow, two pieces of code want the same name; modules are Rust's way to organize code into named scopes so names don't collide.
- [13.2 Defining modules and paths](https://learnrust.net/chapter-13/defining-modules.md): How to define nested modules, refer to items with absolute and relative paths (crate::, self::, super::), and bring names into scope with use.
- [13.3 Visibility: pub](https://learnrust.net/chapter-13/visibility-pub.md): Items are private by default; pub exposes them, pub(crate) limits exposure to the crate, and struct fields are made public one at a time, which is encapsulation.
- [13.4 Splitting code into multiple files](https://learnrust.net/chapter-13/splitting-code-into-files.md): Moving a module into its own file with mod foo and foo.rs, directory modules with mod.rs or named files: the one lesson that replaces C++'s entire header system.
- [13.5 Binary and library crates](https://learnrust.net/chapter-13/binary-and-library-crates.md): The difference between a binary crate (main.rs) and a library crate (lib.rs), having both in one package, and why the split matters for testing and reuse.
- [13.6 Cargo in depth](https://learnrust.net/chapter-13/cargo-in-depth.md): A tour of what Cargo does beyond run and build: profiles, useful commands, a glance at workspaces and features, and Cargo.toml as the project's control panel.
- [13.7 Documentation comments](https://learnrust.net/chapter-13/documentation-comments.md): Doc comments with /// and //!, Markdown in docs, building a docs website with cargo doc, and why Rust's documentation culture is one of its quiet strengths.
- [13.8 Reading documentation](https://learnrust.net/chapter-13/reading-documentation.md): How to actually read a method signature you've never seen on docs.rs and the standard library docs: a practical skill that makes you self-sufficient.
- [13.x Chapter 13 summary and quiz](https://learnrust.net/chapter-13/chapter-13-summary-and-quiz.md): Review of modules, paths, visibility, splitting code into files, crates, Cargo, and documentation, with a chapter quiz and a small organizational exercise.

## Chapter 14: Testing

- [14.1 Introduction to testing](https://learnrust.net/chapter-14/introduction-to-testing.md): Why automated tests matter, what makes a good test, and why Rust treats testing as a built-in habit rather than an external add-on.
- [14.2 Writing tests](https://learnrust.net/chapter-14/writing-tests.md): The #[test] attribute, the assert! family, assert_eq! and assert_ne!, testing for panics with #[should_panic], and tests that return Result.
- [14.3 Organizing unit tests](https://learnrust.net/chapter-14/organizing-unit-tests.md): The conventional #[cfg(test)] mod tests pattern, why tests live next to the code they test, and how unit tests can reach a module's private functions.
- [14.4 Integration tests](https://learnrust.net/chapter-14/integration-tests.md): Integration tests live in the tests/ directory, see only a crate's public API, and exercise it the way a real user would: the lib.rs split paying off.
- [14.5 Doc tests](https://learnrust.net/chapter-14/doc-tests.md): The examples in your /// doc comments compile and run as tests, so documentation can't drift out of sync with the code: how to write them and what they catch.
- [14.6 Running tests](https://learnrust.net/chapter-14/running-tests.md): Controlling cargo test: filtering by name, seeing println output, ignoring slow tests with #[ignore], and why tests run in parallel by default.
- [14.x Chapter 14 summary and quiz](https://learnrust.net/chapter-14/chapter-14-summary-and-quiz.md): Review of writing and organizing tests, integration and doc tests, and running tests, with a chapter quiz and a test-writing exercise.

## Chapter 15: Generics

- [15.1 The problem generics solve](https://learnrust.net/chapter-15/the-problem-generics-solve.md): Writing the same function for i32, then for char, then admitting defeat: the duplication that motivates generics, and what a type parameter is.
- [15.2 Generic functions](https://learnrust.net/chapter-15/generic-functions.md): Writing functions generic over a type with <T>, the kinds of generic code that compile without bounds, and the exact error you get when the body needs more.
- [15.3 Generic structs and enums](https://learnrust.net/chapter-15/generic-structs-and-enums.md): Structs and enums can take type parameters too; the reveal that Option and Vec were generic all along, plus type aliases and a glance at const generics.
- [15.4 Generic methods](https://learnrust.net/chapter-15/generic-methods.md): Implementing methods on generic types with impl<T> blocks, and writing methods that exist only for a specific instantiation like Point<f64>.
- [15.5 Monomorphization](https://learnrust.net/chapter-15/monomorphization.md): What the compiler actually produces from generic code: a specialized copy per type used, why this makes generics zero-cost at runtime, and the binary-size tradeoff.
- [15.x Chapter 15 summary and quiz](https://learnrust.net/chapter-15/chapter-15-summary-and-quiz.md): Review of the problem generics solve, generic functions, structs, enums, methods, and monomorphization, with a chapter quiz and an exercise.

## Chapter 16: Traits

- [16.1 Introduction to traits](https://learnrust.net/chapter-16/introduction-to-traits.md): A trait defines shared behavior that many types can implement; defining a trait, implementing it for a type, and why traits are the structural center of Rust.
- [16.2 Default method implementations](https://learnrust.net/chapter-16/default-method-implementations.md): A trait can provide default method bodies that implementing types get for free, can override, and can build on by calling other trait methods.
- [16.3 Trait bounds](https://learnrust.net/chapter-16/trait-bounds.md): Trait bounds restrict a generic type parameter to types that implement a trait, finally making largest compile; the T: Trait syntax, where clauses, and multiple bounds.
- [16.4 impl Trait](https://learnrust.net/chapter-16/impl-trait.md): The impl Trait shorthand for some type implementing a trait, in argument and return position, and when it beats spelling out a generic parameter.
- [16.5 Deriving traits](https://learnrust.net/chapter-16/deriving-traits.md): A tour of the derivable traits (Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default), what each unlocks, and when you can't derive.
- [16.6 Display and ToString](https://learnrust.net/chapter-16/display-and-tostring.md): Implementing the Display trait for human-facing {} output, how it differs from Debug, and the free ToString conversion that Display unlocks.
- [16.7 Operator overloading with std::ops](https://learnrust.net/chapter-16/operator-overloading.md): Every operator is a trait: implementing Add, Mul, Index, and Neg for your own types, one lesson where C++ needs a whole chapter.
- [16.8 Conversions: From and Into](https://learnrust.net/chapter-16/from-and-into.md): The From and Into traits are the blessed way to convert between types; TryFrom for fallible conversions, and how the ? operator uses From to convert error types.
- [16.9 Trait objects: dyn Trait](https://learnrust.net/chapter-16/trait-objects.md): Trait objects let a collection hold different types that share a trait, with the method chosen at runtime; dynamic dispatch, Box<dyn Trait>, and the tradeoff with generics.
- [16.10 Code reuse without inheritance](https://learnrust.net/chapter-16/code-reuse-without-inheritance.md): Rust has no inheritance; how composition, default trait methods, and trait objects cover what inheritance was used for, and what to reach for when you miss it.
- [16.x Chapter 16 summary and quiz](https://learnrust.net/chapter-16/chapter-16-summary-and-quiz.md): Review of traits, default methods, bounds, impl Trait, deriving, Display, operators, From/Into, trait objects, and composition, with a chapter quiz and a capstone.

## Chapter 17: Lifetimes

- [17.1 What lifetimes are](https://learnrust.net/chapter-17/what-lifetimes-are.md): Every reference has a lifetime, the span during which it's valid; you've used them implicitly since chapter 9, and this chapter just makes them explicit.
- [17.2 Lifetime annotations in functions](https://learnrust.net/chapter-17/lifetime-annotations-in-functions.md): The 'a syntax on a function that returns a reference, the longest example, and the crucial point that an annotation describes a relationship, it never extends a lifetime.
- [17.3 Lifetimes in structs](https://learnrust.net/chapter-17/lifetimes-in-structs.md): How a struct can hold a reference by declaring a lifetime parameter, what the annotation guarantees, and why owned fields remain the simpler default.
- [17.4 Elision rules](https://learnrust.net/chapter-17/elision-rules.md): The three lifetime elision rules that let the compiler infer lifetimes on most function signatures, applied to functions you've already written without thinking about them.
- [17.5 The 'static lifetime](https://learnrust.net/chapter-17/the-static-lifetime.md): The 'static lifetime is the whole-program lifetime of string literals, and why adding 'static to silence the borrow checker is usually the wrong fix.
- [17.x Chapter 17 summary and quiz](https://learnrust.net/chapter-17/chapter-17-summary-and-quiz.md): Review of what lifetimes are, annotations on functions and structs, the elision rules, and the 'static lifetime, with a chapter quiz.

## Chapter 18: Common Collections

- [18.1 Introduction to collections](https://learnrust.net/chapter-18/introduction-to-collections.md): What the standard collections are, why they live on the heap and can grow at runtime, and a map of Vec, String, and HashMap before diving in.
- [18.2 Vec: creating and updating](https://learnrust.net/chapter-18/vec-creating-and-updating.md): Creating vectors with Vec::new and the vec! macro, pushing and popping, and the crucial difference between get (returns Option) and [] indexing (panics out of bounds).
- [18.3 Vec: iterating and borrowing](https://learnrust.net/chapter-18/vec-iterating-and-borrowing.md): Iterating a vector by shared reference, mutable reference, and by value, and why the borrow checker forbids modifying a vector while iterating over it.
- [18.4 Vec: capacity and growth](https://learnrust.net/chapter-18/vec-capacity-and-growth.md): The difference between a vector's length and its capacity, how pushing triggers reallocation, and using with_capacity to avoid repeated reallocations.
- [18.5 String as a collection](https://learnrust.net/chapter-18/string-as-a-collection.md): String is a UTF-8 byte buffer: why s[0] doesn't compile, the difference between chars() and bytes(), and why slicing a string can panic.
- [18.6 HashMap](https://learnrust.net/chapter-18/hashmap.md): Storing key-value pairs in a HashMap: insert and get, the entry API for update-or-insert, and how ownership works for keys and values.
- [18.7 Arrays and slices, revisited](https://learnrust.net/chapter-18/arrays-and-slices-revisited.md): Fixed-size arrays [T; N] in depth, when a fixed length wins, slices as the universal parameter type that accepts arrays and vectors alike, and nested data for 2D grids.
- [18.8 Choosing a collection](https://learnrust.net/chapter-18/choosing-a-collection.md): A decision guide to the standard collections: when VecDeque, HashSet, and BTreeMap beat the core three, with a quick comparison table.
- [18.x Chapter 18 summary and quiz](https://learnrust.net/chapter-18/chapter-18-summary-and-quiz.md): Review of Vec, String as UTF-8, HashMap, arrays and slices, and choosing a collection, with a chapter quiz and a capstone program.

## Chapter 19: Closures and Iterators

- [19.1 Closures](https://learnrust.net/chapter-19/closures.md): Closures are functions you can write inline and that capture variables from the surrounding scope, by reference or by move.
- [19.2 Closures and the Fn traits](https://learnrust.net/chapter-19/closures-and-the-fn-traits.md): How to take a closure as a parameter or return one, using the Fn, FnMut, and FnOnce traits, plus where plain function pointers fit.
- [19.3 The Iterator trait](https://learnrust.net/chapter-19/the-iterator-trait.md): What an iterator really is: the next method, the Item associated type, the iter/iter_mut/into_iter trio, and why iterators are lazy.
- [19.4 Iterator adapters](https://learnrust.net/chapter-19/iterator-adapters.md): The lazy transformers: map, filter, enumerate, zip, rev, and chain build one iterator from another without doing any work until consumed.
- [19.5 Consuming iterators](https://learnrust.net/chapter-19/consuming-iterators.md): The methods that drive an iterator to a result: collect and the turbofish, sum, count, fold, find, and the any/all short-circuiting checks.
- [19.6 For loops, demystified](https://learnrust.net/chapter-19/for-loops-demystified.md): How a for loop desugars into IntoIterator plus repeated next calls, finally paying off the promise made back in chapter 7.
- [19.7 Loops vs iterators](https://learnrust.net/chapter-19/loops-vs-iterators.md): Iterator pipelines compile to the same machine code as hand-written loops: the zero-cost claim, a benchmark, and when each style wins.
- [19.x Chapter 19 summary and quiz](https://learnrust.net/chapter-19/chapter-19-summary-and-quiz.md): Review of closures, the Fn traits, the Iterator trait, adapters, consumers, and the for-loop desugaring, with a capstone exercise.

## Chapter 20: Building Command-Line Programs

- [20.1 Command-line arguments](https://learnrust.net/chapter-20/command-line-arguments.md): Reading the arguments a user passes to your program with std::env::args, collecting them into a Vec, and the convention of argument zero.
- [20.2 Reading and writing files](https://learnrust.net/chapter-20/reading-and-writing-files.md): The one-line conveniences fs::read_to_string and fs::write for small files, and File with BufReader and BufWriter for big ones.
- [20.3 stdin, stdout, and stderr](https://learnrust.net/chapter-20/stdin-stdout-stderr.md): The three standard streams every program has, piping between programs, why errors belong on stderr, and exit codes.
- [20.4 Environment variables](https://learnrust.net/chapter-20/environment-variables.md): Reading configuration from the environment with env::var, the Result it returns, and when an env var beats a command-line flag.
- [20.5 Project: a text-search tool, part 1](https://learnrust.net/chapter-20/text-search-tool-part-1.md): Building a real grep-like tool: parsing arguments into a Config, reading the file, and splitting logic into lib.rs and a thin main with Result everywhere.
- [20.6 Project: a text-search tool, part 2](https://learnrust.net/chapter-20/text-search-tool-part-2.md): Finishing minigrep: a search function written test-first, a case-insensitive flag from an environment variable, errors to stderr, and an iterator refactor.
- [20.x Chapter 20 summary and quiz](https://learnrust.net/chapter-20/chapter-20-summary-and-quiz.md): Review of command-line arguments, files, the standard streams, environment variables, and the minigrep project, with an extension exercise.

## Chapter 21: Smart Pointers

- [21.1 Introduction to smart pointers](https://learnrust.net/chapter-21/introduction-to-smart-pointers.md): What a smart pointer is: a value that owns what it points to and adds behavior, and why Box, Rc, and RefCell exist when plain references don't suffice.
- [21.2 Box<T>](https://learnrust.net/chapter-21/box.md): The simplest smart pointer: heap allocation for a single value, and the recursive types whose infinite-size error Box exists to fix.
- [21.3 Deref and deref coercion](https://learnrust.net/chapter-21/deref-and-deref-coercion.md): The Deref trait that lets a smart pointer stand in for its contents, and the deref coercion that finally explains why &String works as &str.
- [21.4 Drop in depth](https://learnrust.net/chapter-21/drop-in-depth.md): The Drop trait behind automatic cleanup, the order values are dropped in, dropping early with std::mem::drop, and the RAII pattern named.
- [21.5 Rc<T>](https://learnrust.net/chapter-21/rc.md): The reference-counted smart pointer for shared ownership: many owners of one value, freed when the last one drops, with clone-the-handle semantics.
- [21.6 RefCell and interior mutability](https://learnrust.net/chapter-21/refcell-and-interior-mutability.md): Moving the borrow check to runtime with RefCell, mutating through a shared reference safely, and the Rc<RefCell<T>> combination.
- [21.7 Reference cycles and Weak](https://learnrust.net/chapter-21/reference-cycles-and-weak.md): The one memory leak Rust doesn't prevent: two Rcs pointing at each other, and how Weak references break the cycle.
- [21.x Chapter 21 summary and quiz](https://learnrust.net/chapter-21/chapter-21-summary-and-quiz.md): Review of Box, Deref, Drop, Rc, RefCell, and Weak, the smart pointers and traits that let you reach for the heap and share ownership deliberately.

## Chapter 22: Fearless Concurrency

- [22.1 Threads](https://learnrust.net/chapter-22/threads.md): Running code concurrently with thread::spawn, joining handles to wait for results, and why spawned closures usually need move.
- [22.2 Message passing: channels](https://learnrust.net/chapter-22/message-passing-channels.md): Threads communicating by sending values through an mpsc channel, where send moves ownership and the compiler prevents use-after-send.
- [22.3 Shared state: Mutex and Arc](https://learnrust.net/chapter-22/shared-state-mutex-and-arc.md): Sharing the same data across threads safely: Mutex for exclusive access via locking, and Arc for thread-safe shared ownership.
- [22.4 Send and Sync](https://learnrust.net/chapter-22/send-and-sync.md): The two marker traits the compiler uses to decide what's safe to move or share between threads, and why concurrency safety is automatic.
- [22.5 Data parallelism with rayon](https://learnrust.net/chapter-22/data-parallelism-with-rayon.md): Turning a sequential iterator into a parallel one by changing iter to par_iter, and the ecosystem victory lap of adding one dependency.
- [22.x Chapter 22 summary and quiz](https://learnrust.net/chapter-22/chapter-22-summary-and-quiz.md): Review of threads, channels, Mutex and Arc, the Send and Sync marker traits, and rayon, with a capstone parallel computation.

## Chapter 23: Async Rust

- [23.1 What async is, and when you want it](https://learnrust.net/chapter-23/what-async-is.md): The difference between IO-bound and CPU-bound work, threads versus tasks, and an honest account of when async is the right tool and when it isn't.
- [23.2 async/await and Futures](https://learnrust.net/chapter-23/async-await-and-futures.md): How async functions produce lazy Futures, what .await does, and why you need a runtime to make any of it actually run.
- [23.3 Using Tokio](https://learnrust.net/chapter-23/using-tokio.md): Adding the Tokio runtime, the #[tokio::main] attribute, spawning tasks, async sleep versus blocking sleep, and a small concurrent example.
- [23.4 Async pitfalls](https://learnrust.net/chapter-23/async-pitfalls.md): A field guide to where async bites: blocking the executor, the Send requirement on spawned tasks, and cancellation at await points.
- [23.x Chapter 23 summary and quiz](https://learnrust.net/chapter-23/chapter-23-summary-and-quiz.md): Review of when to use async, async/await and Futures, the Tokio runtime, and the main async pitfalls, with a conceptual exercise.

## Chapter 24: Macros

- [24.1 Declarative macros: macro_rules!](https://learnrust.net/chapter-24/declarative-macros.md): Code that writes code: how macro_rules! matches patterns and expands into source, paying off the println! mystery from lesson 1.1.
- [24.2 When to write a macro](https://learnrust.net/chapter-24/when-to-write-a-macro.md): Choosing a macro only when a function or generic can't do the job, plus a first look at macro hygiene.
- [24.3 Procedural macros: an overview](https://learnrust.net/chapter-24/procedural-macros-overview.md): The three kinds of procedural macro behind derive, attributes, and function-like macros, what powers serde and tokio, and why you read them more than write them.
- [24.x Chapter 24 summary and quiz](https://learnrust.net/chapter-24/chapter-24-summary-and-quiz.md): Review of declarative macro_rules! macros, when to use a macro versus a function or generic, and the three kinds of procedural macro.

## Chapter 25: Unsafe Rust and FFI

- [25.1 What unsafe actually means](https://learnrust.net/chapter-25/what-unsafe-means.md): The five powers unsafe unlocks, what stays checked even inside unsafe, and the safety-comment culture that treats unsafe as a contract rather than an off-switch.
- [25.2 Raw pointers](https://learnrust.net/chapter-25/raw-pointers.md): The *const T and *mut T raw pointers: how they differ from references, creating them safely, and why dereferencing them requires unsafe.
- [25.3 Unsafe functions and safe abstractions](https://learnrust.net/chapter-25/unsafe-functions-and-safe-abstractions.md): Functions marked unsafe and their preconditions, and the core pattern of wrapping unsafe code in a safe API, with split_at_mut as the example.
- [25.4 Calling C from Rust](https://learnrust.net/chapter-25/calling-c-from-rust.md): Foreign function interface: declaring C functions with extern C, why every foreign call is unsafe, and a real libc example.
- [25.5 Calling Rust from C](https://learnrust.net/chapter-25/calling-rust-from-c.md): Exposing Rust functions to other languages with extern C and no_mangle, building a cdylib, and Rust-in-anything as the closing pitch.
- [25.x Chapter 25 summary and quiz](https://learnrust.net/chapter-25/chapter-25-summary-and-quiz.md): Review of what unsafe means, the five superpowers, raw pointers, safe abstractions, and calling C from Rust and Rust from C.

## Chapter 26: Final Project: Multithreaded Web Server

- [26.1 A single-threaded web server](https://learnrust.net/chapter-26/single-threaded-web-server.md): Building a working web server from scratch: listening on a TCP port, reading an HTTP request, and writing an HTTP response by hand.
- [26.2 From single to multithreaded](https://learnrust.net/chapter-26/from-single-to-multithreaded.md): The design conversation: why thread-per-request doesn't scale, what a thread pool is, and the interface we'll build toward.
- [26.3 Building the thread pool](https://learnrust.net/chapter-26/building-the-thread-pool.md): Implementing the pool: workers, a channel to send jobs, an Arc<Mutex> shared receiver, and the Box<dyn FnOnce + Send> job type that ties the course together.
- [26.4 Graceful shutdown](https://learnrust.net/chapter-26/graceful-shutdown.md): Finishing the server with a clean shutdown: a Drop implementation that closes the channel and joins every worker, and the end of the course.

## Appendix A: Useful Crates and Tools

- [A.1 Useful crates and tools](https://learnrust.net/appendix-a/useful-crates-and-tools.md): A starter map of the Rust ecosystem: the crates and command-line tools you will reach for most often, and how to evaluate the ones you find yourself.

## Appendix B: Rust Editions in Detail

- [B.1 Rust editions in detail](https://learnrust.net/appendix-b/rust-editions-in-detail.md): What each Rust edition actually changed, from the 2015 baseline through 2018, 2021, and 2024, and why none of it broke older code.

## Appendix C: The End?

- [C.1 The end?](https://learnrust.net/appendix-c/the-end.md): Where to go from here once the course is over: the projects to build, the resources to read next, the community to join, and a thank-you.

## Sitemap

See the full [sitemap](https://learnrust.net/sitemap.md) for all pages.
