liveBook · Manning

What you will learn in Idiomatic Rust

Code like a Rustacean

by Brenden Matthews

Chapter by chapter

Chapter 1: Rust-y patterns

1.1 What this book covers · 1.2 What design patterns are · 1.3 Why this book is different · 1.4 Tools you’ll need · 1.5 Summary

What you learn in chapter 1 →

Chapter 2: Rust’s basic building blocks

2.1 Generics · 2.1.1 A Turing-complete type system · 2.1.2 Why generics? · 2.1.3 Basics of generics · 2.1.4 Exploring Rust’s Option · 2.1.5 Marker structs and phantom types · 2.1.6 Generic parameter trait bounds · 2.2 Traits · 2.2.1 Why traits are not object-oriented programming · 2.2.2 What’s in a trait? · 2.2.3 Understanding traits by examining object-oriented code · 2.2.4 Combining generics and traits · 2.2.5 Deriving traits automatically · 2.2.6 Trait objects · 2.3 Summary

What you learn in chapter 2 →

Chapter 3: Code flow

3.1 A tour of pattern matching · 3.1.1 Basics of pattern matching · 3.1.2 Clean matches with the ? operator · 3.2 Functional Rust · 3.2.1 Basics of functional programming in Rust · 3.2.2 Closure variable capture · 3.2.3 Examining iterators · 3.2.4 Obtaining an iterator with iter(), into_iter(), and iter_mut() · 3.2.5 Iterator features · 3.3 Summary

What you learn in chapter 3 →

Chapter 4: Introductory patterns

4.1 Resource acquisition is initialization · 4.1.1 Understanding RAII in C and C++ · 4.1.2 A tour of RAII in Rust · 4.1.3 Summarizing RAII in Rust · 4.2 Passing arguments by value vs. reference · 4.2.1 Passing by value · 4.2.2 Passing by reference · 4.2.3 When to do what: Passing by value vs. reference · 4.3 Constructors · 4.4 Object-member visibility and access · 4.5 Error handling · 4.6 Global state · 4.6.1 lazy-static.rs · 4.6.2 once_cell · 4.6.3 static_init · 4.6.4 std::cell::OnceCell · 4.7 Summary

What you learn in chapter 4 →

Chapter 5: Design patterns: Beyond the basics

5.1 Metaprogramming with macros · 5.1.1 A basic declarative macro in Rust · 5.1.2 When to use macros · 5.1.3 Using macros to write mini-DSLs · 5.1.4 Using macros for DRY · 5.2 Optional function arguments · 5.2.1 Examining optional arguments in Python · 5.2.2 Examining optional arguments in C++ · 5.2.3 Optional arguments in Rust or the lack thereof · 5.2.4 Emulating optional arguments with traits · 5.3 Builder pattern · 5.3.1 Implementing the builder pattern · 5.3.2 Enhancing our builder with traits · 5.3.3 Enhancing our builder with macros · 5.4 Fluent interface pattern · 5.4.1 A fluent builder · 5.4.2 Test-driving our fluent builder · 5.5 Observer pattern · 5.5.1 Why not callbacks? · 5.5.2 Implementing an observer · 5.6 Command pattern · 5.6.1 Defining the command pattern · 5.6.2 Implementing the command pattern · 5.7 Newtype pattern · 5.8 Summary

What you learn in chapter 5 →

Chapter 6: Designing a library

6.1 Meditate on good library design · 6.2 Do one thing, do it well, and do it correctly · 6.3 Avoid excessive abstraction · 6.4 Stick to basic types · 6.5 Use the tools · 6.6 Good artists copy; great artists steal (from the standard library) · 6.7 Document everything, and provide examples · 6.8 Don’t break the user’s code · 6.9 Think of the state · 6.10 Consider the aesthetics · 6.11 Examining Rust library ergonomics · 6.11.1 Revisiting linked lists · 6.11.2 Using rustdoc to improve our API design · 6.11.3 Improving our linked list with more tests · 6.11.4 Making our library easier for others to debug · 6.12 Summary

What you learn in chapter 6 →

Chapter 7: Using traits, generics, and structs for specialized tasks

7.1 Const generics · 7.2 Implementing traits for external crate types · 7.2.1 Wrapper structs · 7.2.2 Using Deref to unwrap a wrapped struct · 7.3 Extension traits · 7.4 Blanket traits · 7.5 Marker traits · 7.6 Struct tagging · 7.7 Reference objects · 7.8 Summary

What you learn in chapter 7 →

Chapter 8: State machines, coroutines, macros, and preludes

8.1 Trait state machine · 8.2 Coroutines · 8.3 Procedural macros · 8.4 Preludes · 8.5 Summary

What you learn in chapter 8 →

Chapter 9: Immutability

9.1 The benefits of immutability · 9.2 Why immutability is not a magic bullet · 9.3 How to think about immutable data · 9.4 Understanding immutability in Rust · 9.5 Reviewing the basics of immutability in Rust · 9.6 Using traits to make (almost) anything immutable · 9.7 Using Cow for immutability · 9.8 Using crates for immutable data structures · 9.8.1 Using im · 9.8.2 Using rpds · 9.9 Summary

What you learn in chapter 9 →

Chapter 10: Antipatterns

10.1 What is an antipattern? · 10.2 Using unsafe · 10.2.1 What does unsafe do? · 10.2.2 Where can you use unsafe? · 10.2.3 When should you use unsafe? · 10.2.4 Should you worry about unsafe? · 10.3 Using unwrap() · 10.4 Not using Vec · 10.5 Too many clones · 10.6 Using Deref to emulate polymorphism · 10.7 Global data and singletons · 10.8 Too many smart pointers · 10.9 Where to go from here · 10.10 Summary

What you learn in chapter 10 →

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.