liveBook · Manning

What you will learn in Learn Rust in a Month of Lunches

by Dave MacLeod

Chapter by chapter

Chapter 1: Some basics

The chapter introduction previews the basics and explains that even simple Rust types involve choices, while the compiler strictly checks programs before they run.

1.1 Introducing Rust · 1.1.1 A pep talk · 1.1.2 Rust is like a critical spouse · 1.2 Comments · 1.3 Primitive types: Integers, characters, and strings · 1.4 Type inference · 1.5 Floats · 1.6 “Hello, World!” and printing · 1.7 Declaring variables and code blocks · 1.8 Display and Debug · 1.9 Smallest and largest numbers · 1.10 Mutability (changing) · 1.11 Shadowing · 1.12 Summary

What you learn in chapter 1 →

Chapter 2: Memory, variables, and ownership

Introduces Rust’s focus on memory use and ownership without yet explaining the memory mechanisms.

2.1 The stack, the heap, pointers, and references · 2.2 Strings · 2.3 const and static · 2.4 More on references · 2.5 Mutable references · 2.5.1 Rust’s reference rules · 2.5.2 Situation 1: Only one mutable reference · 2.5.3 Situation 2: Only immutable references · 2.5.4 Situation 3: The problem situation · 2.6 Shadowing again · 2.7 Giving references to functions · 2.8 Copy types · 2.9 Variables without values · 2.10 More about printing · 2.11 Summary

What you learn in chapter 2 →

Chapter 3: More complex types

The introduction distinguishes three collection types and defines control flow as changing how code runs depending on the situation.

3.1 Collection types · 3.1.1 Arrays · 3.1.2 Vectors · 3.1.3 Tuples · 3.2 Control flow · 3.2.1 Basic control flow · 3.2.2 Match statements · 3.2.3 Loops · 3.3 Summary

What you learn in chapter 3 →

Chapter 4: Building your own types

Introduces structs and enums as ways to build Rust types and methods as functions attached to those types.

4.1 A quick overview of structs and enums · 4.1.1 Structs · 4.1.2 Enums · 4.1.3 Casting enums into integers · 4.1.4 Enums to use multiple types · 4.1.5 Implementing structs and enums · 4.2 Destructuring · 4.3 References and the dot operator · 4.4 Summary

What you learn in chapter 4 →

Chapter 5: Generics, option, and result

The chapter introduces generics, Option, and Result as tools for working with types, possibly missing values, and operations that might fail.

5.1 Generics · 5.2 Option and Result · 5.2.1 Option · 5.2.2 Result · 5.2.3 Some other ways to do pattern matching · 5.3 Summary

What you learn in chapter 5 →

Chapter 6: More collections, more error handling

This chapter introduction previews additional Rust collections and later discussions of the ? operator, panic, and unwrap.

6.1 Other collections · 6.1.1 HashMap (and BTreeMap) · 6.1.2 HashSet and BTreeSet · 6.1.3 BinaryHeap · 6.1.4 VecDeque · 6.2 The ? operator · 6.3 When panic and unwrap are good · 6.4 Summary

What you learn in chapter 6 →

Chapter 7: Traits: Making different types do the same thing

This introduction previews the chapter’s trait topics without explaining how traits work.

7.1 Traits: The basics · 7.1.1 All you need are the method signatures · 7.1.2 More complex examples · 7.1.3 Traits as bounds · 7.1.4 Traits are like qualifications · 7.2 The From trait · 7.3 The orphan rule · 7.4 Getting around the orphan rule with newtypes · 7.5 Taking a String and a &str in a function · 7.6 Summary

What you learn in chapter 7 →

Chapter 8: Iterators and closures

The chapter introduces method chaining as passing one method’s output into the next and identifies iterators and closures as tools used with that style.

8.1 Chaining methods · 8.2 Iterators · 8.3 Closures and closures inside iterators · 8.3.1 Closures inside of methods · 8.3.2 Closures: Lazy and fast · 8.3.3 |_| in a closure · 8.4 Summary

What you learn in chapter 8 →

Chapter 9: Iterators and closures again!

The introduction explains why learning more iterator and closure methods is worthwhile and suggests how to approach them without memorizing every method.

9.1 Helpful methods for closures and iterators · 9.1.1 Mapping and filtering · 9.1.2 Some more iterator and related methods · 9.1.3 Checking and finding items inside iterators · 9.1.4 Cycling, zipping, folding, and more · 9.2 The dbg! macro and .inspect · 9.3 Summary

What you learn in chapter 9 →

Chapter 10: Lifetimes and interior mutability

The introduction explains why lifetime annotations may be needed and introduces interior mutability as a way to change values safely without a mutable reference.

10.1 Types of &str · 10.2 Lifetime annotations · 10.2.1 Lifetimes in functions · 10.2.2 Lifetime annotations in types · 10.2.3 The anonymous lifetime · 10.3 Interior mutability · 10.3.1 Cell · 10.3.2 RefCell · 10.3.3 Mutex · 10.3.4 RwLock · 10.4 Summary

What you learn in chapter 10 →

Chapter 11: Multiple threads and a lot more

This chapter introduction previews advanced Rust topics, including type aliases, Cow, Rc, and multiple threads, without explaining them in depth.

11.1 Importing and renaming inside a function · 11.2 The todo! macro · 11.3 Type aliases · 11.4 Cow · 11.5 Rc · 11.5.1 Why Rc exists · 11.5.2 Using Rc in practice · 11.5.3 Avoiding lifetime annotations with Rc · 11.6 Multiple threads · 11.6.1 Spawning threads · 11.6.2 Using JoinHandles to wait for threads to finish · 11.6.3 Types of closures · 11.6.4 Using the move keyword · 11.7 Summary

What you learn in chapter 11 →

Chapter 12: More on closures, generics, and threads

The introduction connects the chapter’s new tools to familiar Rust concepts and gives a few high-level distinctions.

12.1 Closures as arguments · 12.1.1 Some simple closures · 12.1.2 The relationship between FnOnce, FnMut, and Fn · 12.1.3 Closures are all unique · 12.1.4 A closure example · 12.2 impl Trait · 12.2.1 Regular generics compared to impl Trait · 12.2.2 Returning closures with impl Trait · 12.3 Arc · 12.4 Scoped threads · 12.5 Channels · 12.5.1 Channel basics · 12.5.2 Implementing a channel · 12.6 Summary

What you learn in chapter 12 →

Chapter 13: Box and Rust documentation

The introduction explains why Rust documentation is transferable to read, why Box matters, and how to recognize attributes.

13.1 Reading Rust documentation · 13.1.1 assert_eq! · 13.1.2 Searching · 13.1.3 The [src] button · 13.1.4 Information on traits · 13.1.5 Attributes · 13.2 Box · 13.2.1 Some Box basics · 13.2.2 Putting a Box around traits · 13.2.3 Using a Box to handle multiple error types · 13.2.4 Downcasting to a concrete type · 13.3 Summary

What you learn in chapter 13 →

Chapter 14: Testing and building your code from tests

The introduction explains why growing Rust programs need structure and tests, then outlines the test-driven development cycle.

14.1 Crates and modules · 14.1.1 Module basics · 14.1.2 More on how the pub keyword works · 14.1.3 Modules inside modules · 14.2 Testing · 14.2.1 Just add #[test], and now it’s a test · 14.2.2 What happens when tests fail · 14.2.3 Writing multiple tests · 14.3 Test-driven development · 14.3.1 Building a calculator: Starting with the tests · 14.3.2 Putting the calculator together · 14.4 Summary

What you learn in chapter 14 →

Chapter 15: Default, the builder pattern, and Deref

The introduction explains why builder-style method chaining and Deref can be useful for creating and extending types.

15.1 Implementing Default · 15.2 The builder pattern · 15.2.1 Writing builder methods · 15.2.2 Adding a final check to the builder pattern · 15.2.3 Making the builder pattern more rigorous · 15.3 Deref and DerefMut · 15.3.1 Deref basics · 15.3.2 Implementing Deref · 15.3.3 Implementing DerefMut · 15.3.4 Using Deref the wrong way · 15.4 Summary

What you learn in chapter 15 →

Chapter 16: Const, “unsafe” Rust, and external crates

The chapter introduces const generics and const functions, then previews unsafe Rust and external crates.

16.1 Const generics · 16.2 Const functions · 16.3 Mutable statics · 16.4 Unsafe Rust · 16.4.1 Overview of unsafe Rust · 16.4.2 Using static mut in unsafe Rust · 16.4.3 Rust’s most famous unsafe method · 16.4.4 Methods ending in _unchecked · 16.5 Introducing external crates · 16.5.1 Crates and Cargo.toml · 16.5.2 Using the rand crate · 16.5.3 Rolling some dice with rand · 16.6 Summary

What you learn in chapter 16 →

Chapter 17: Rust’s most popular crates

The chapter introduces widely used external crates as practical additions to Rust and briefly states what blanket trait implementations make possible.

17.1 serde · 17.2 Time in the standard library · 17.3 chrono · 17.3.1 Checking the code inside external crates · 17.3.2 Back to chrono · 17.4 Rayon · 17.5 Anyhow and thiserror · 17.5.1 Anyhow · 17.5.2 thiserror · 17.6 Blanket trait implementations · 17.7 lazy_static and once_cell · 17.7.1 Lazy static: Lazily evaluated statics · 17.7.2 OnceCell: A cell to only write to once · 17.8 Summary

What you learn in chapter 17 →

Chapter 18: Rust on your computer

This introduction explains why working on a computer offers capabilities beyond the Playground and identifies Cargo as Rust’s package manager.

18.1 Cargo · 18.1.1 Why everyone uses Cargo · 18.1.2 Using Cargo and what Rust does while it compiles · 18.2 Working with user input · 18.2.1 User input through stdin · 18.2.2 Accessing command-line arguments · 18.2.3 Accessing environment variables · 18.3 Using files · 18.3.1 Creating files · 18.3.2 Opening existing files · 18.3.3 Using OpenOptions to work with files · 18.4 cargo doc · 18.5 Summary

What you learn in chapter 18 →

Chapter 19: More crates and async Rust

The introduction previews reqwest and async Rust and explains why feature flags can help reduce compilation time.

19.1 The reqwest crate · 19.2 Feature flags · 19.3 Async Rust · 19.3.1 Async basics · 19.3.2 Checking whether a Future is ready · 19.3.3 Using an async run time · 19.3.4 Some other details about async Rust · 19.4 Summary

What you learn in chapter 19 →

Chapter 20: A tour of the standard library

Introduces a brief tour of the Rust standard library and previews the types and features the next sections will cover.

20.1 Arrays · 20.1.1 Arrays now implement Iterator · 20.1.2 Destructuring and mapping arrays · 20.1.3 Using from_fn to make arrays · 20.2 char · 20.3 Integers · 20.3.1 Checked operations · 20.3.2 The Add trait and other similar traits · 20.4 Floats · 20.5 Associated items and associated constants · 20.5.1 Associated functions · 20.5.2 Associated types · 20.5.3 Associated consts · 20.6 bool · 20.7 Vec · 20.8 String · 20.9 OsString and CString · 20.10 Summary

What you learn in chapter 20 →

Chapter 21: Continuing the tour

Introduces the second standard-library tour and previews its topics, including macros.

21.1 std::mem · 21.2 Setting panic hooks · 21.3 Viewing backtraces · 21.4 The standard library prelude · 21.5 Other macros · 21.5.1 unreachable! · 21.5.2 column!, line!, file!, and module_path! · 21.5.3 thread_local! · 21.5.4 cfg! · 21.6 Summary

What you learn in chapter 21 →

Chapter 22: Writing your own macros

The introduction explains why writing macros can be useful while warning that their unfamiliar syntax takes practice.

22.1 Why macros exist · 22.2 Writing basic macros · 22.3 Reading macros from the standard library · 22.4 Using macros to keep your code clean · 22.5 Summary

What you learn in chapter 22 →

Chapter 23: Unfinished projects: Projects for you to finish

The chapter introduces runnable but deliberately minimal projects for readers to develop further and explains why they need to be run locally rather than in the Playground.

23.1 Setup for the last two chapters · 23.2 Typing tutor · 23.2.1 Setup and first code · 23.2.2 Developing the code · 23.2.3 Further development and cleanup · 23.2.4 Over to you · 23.3 Wikipedia article summary searcher · 23.3.1 Setup and first code · 23.3.2 Developing the code · 23.3.3 Further development and cleanup · 23.3.4 Over to you · 23.4 Terminal stopwatch and clock · 23.4.1 Setup and first code · 23.4.2 Developing the code · 23.4.3 Further development and cleanup · 23.4.4 Over to you · 23.5 Summary

What you learn in chapter 23 →

Chapter 24: Unfinished projects, continued

Introduces the final chapter’s three unfinished projects for readers to continue after finishing the book.

24.1 Web server word-guessing game · 24.1.1 Setup and first code · 24.1.2 Developing the code · 24.1.3 Further development and cleanup · 24.1.4 Over to you · 24.2 Laser pointer · 24.2.1 Setup and first code · 24.2.2 Developing the code · 24.2.3 Further development and cleanup · 24.2.4 Over to you · 24.3 Directory and file navigator · 24.3.1 Setup and first code · 24.3.2 Developing the code · 24.3.3 Further development and cleanup · 24.3.4 Over to you · 24.4 Summary

What you learn in chapter 24 →

Concepts explained in this book

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.