- Foreword
- Part I
- 1. The Basics
- 1.1. Installing Rust
- 1.2. Your First Program
- 1.3. Variables and Output
- 1.4. Comments
- 1.5. Arithmetic Operators
- 1.6. Operator Precedence
- 1.7. Comparison Operators
- 1.8. if
- 1.9. Scope
- 1.10. else
- 1.11. else if
- 1.12. Logical Operators
- 1.13. let mut
- 1.14. Compound Assignment Operators
- 1.15. stdin
- 1.16. parse
- 1.17. Practice Problems
- 1.18. loop + break
- 1.19. while
- 1.20. for + Ranges
- 1.21. Nested Loops
- 1.22. continue
- 1.23. Types (the Basics)
- 1.24. Types (Numbers in Detail)
- 1.25. char
- 1.26. Escape Characters
- 1.27. if as an Expression
- 2. Functions, Arrays, and Slices
- 2.1. const
- 2.2. Shadowing
- 2.3. Underscore Variables
- 2.4. Tuples
- 2.5. {:?} and the Debug Format
- 2.6. Simple Functions
- 2.7. Function Parameters
- 2.8. Function Return Values
- 2.9. Early return
- 2.10. Recursion
- 2.11. Array Basics
- 2.12. Iterating over Arrays
- 2.13. Slices: &[T]
- 2.14. Slices as Parameters
- 2.15. String Slices: &str
- 3. Structs, Enums, and Pattern Matching
- 3.1. struct (Named Fields)
- 3.2. Tuple structs and Unit structs
- 3.3. enum (C-style)
- 3.4. match on C-style enums
- 3.5. match as an Expression
- 3.6. Block Expressions
- 3.7. enum with Tuple Variants
- 3.8. enum with struct Variants
- 3.9. Destructuring Tuple Variants with match
- 3.10. Destructuring struct Variants with match
- 3.11. Field Shorthand
- 3.12. Tuple Patterns
- 3.13. Slice Patterns
- 3.14. Nested Pattern Matching
- 3.15. The _ Wildcard
- 3.16. Ignoring Multiple Values with ..
- 3.17. Range Patterns
- 3.18. Multiple Values with |
- 3.19. @ Bindings
- 3.20. match Guards
- 3.21. Destructuring Tuples with let
- 3.22. Destructuring structs with let
- 3.23. Destructuring in for Loops
- 3.24. Destructuring in Function Parameters
- 3.25. if let
- 3.26. while let
- 3.27. let else
- 3.28. Associated Functions
- 3.29. Methods
- 3.30. Capital Self
- 4. Ownership and Borrowing
- 4.1. Ownership (the Keychain Analogy)
- 4.2. A Brief Introduction to traits
- 4.3. Moves and Clone
- 4.4. Copy
- 4.5. Borrowing: &
- 4.6. Mutable Borrowing: &mut
- 4.7. The Borrowing Rules
- 4.8. self vs &self vs &mut self
- 4.9. The Stack and the Heap
- 4.10. String
- 4.11. String vs &str
- 4.12. Vec Basics
- 4.13. Vec and Ownership
- 5. Generics, Trait Bounds, and Lifetimes
- 5.1. Generic Functions
- 5.2. Generic structs
- 5.3. Generic enums
- 5.4. The Turbofish Syntax
- 5.5. The Placeholder Type _
- 5.6. Type Aliases
- 5.7. Generic impl
- 5.8. Option<T>
- 5.9. Common Option Methods
- 5.10. Result<T, E>
- 5.11. The ? Operator
- 5.12. traits with Multiple Methods and Default Implementations
- 5.13. trait Bounds
- 5.14. use Basics
- 5.15. The Display trait
- 5.16. Multiple trait Bounds and where
- 5.17. The impl Trait Syntax
- 5.18. Multi-parameter traits
- 5.19. From<T> / Into<T>
- 5.20. Drop
- 5.21. Box<T>
- 5.22. Rc<T>
- 5.23. Deref
- 5.24. Cell<T>
- 5.25. RefCell<T>
- 5.26. Lifetime Basics
- 5.27. Lifetime Elision Rules
- 5.28. Lifetimes on Types
- 5.29. Lifetime Bounds
- 5.30. Supertraits
- 5.31. Common derive traits
- 5.32. Associated Types
- 5.33. Cow<'a, B>
- 6. Closures and Iterators
- 6.1. Function Pointers
- 6.2. Closures in Action
- 6.3. Implementing Closures by Hand
- 6.4. How Closure Kinds Are Inferred
- 6.5. FnOnce / FnMut / Fn
- 6.6. move Closures
- 6.7. Closure Methods on Option / Result
- 6.8. The Iterator trait
- 6.9. What for Loops Really Are
- 6.10. into_iter / iter_mut / iter
- 6.11. Collecting
- 6.12. Aggregation
- 6.13. Combining and Slicing
- 6.14. Transforming and Filtering
- 6.15. Lazy Evaluation
- 7. Cargo, Crates, and the Module System
- 7.1. Cargo and crates.io
- 7.2. mod
- 7.3. File mods
- 7.4. pub Visibility
- 7.5. use
- 7.6. cargo test
- 7.7. pub use
- 7.8. The Orphan Rule
- 7.9. Doc Comments
- 7.10. cargo publish
- 8. Appendix I
- 8.1. Number Literal Formats
- 8.2. Short-circuiting of && and ||
- 8.3. break with a Value
- 8.4. Multiline Strings & Raw String Literals
- 8.5. Format Strings in Depth
- 8.6. structs / enums inside fns
- 8.7. struct Update Syntax
- 8.8. ref Patterns and match Ergonomics
- 8.9. panic! / todo! / unimplemented! / unreachable!
- 8.10. let Chains
- 8.11. Rc Cycles and Weak
- 8.12. Fully Qualified Syntax
- 8.13. A Brief Introduction to DSTs
- 8.14. extern crate
- Part II
- 9. Multithreading
- 9.1. Pointers
- 9.2. thread::spawn
- 9.3. Send / Sync
- 9.4. RefCell under Multithreading
- 9.5. Rc under Multithreading
- 9.6. Arc<T>
- 9.7. Atomic Types
- 9.8. Mutex<T>
- 9.9. RwLock<T>
- 9.10. Poisoning
- 9.11. mpsc
- 9.12. Deadlocks
- 9.13. A Brief Introduction to thread::scope
- 10. Advanced Language Features
- 10.1. dyn Trait Basics
- 10.2. dyn Compatibility
- 10.3. const fn
- 10.4. Associated consts
- 10.5. const Generics
- 10.6. Default Parameters
- 10.7. Operator Overloading
- 10.8. Type Conversion with as
- 10.9. enum Discriminants
- 10.10. An Overview of Attributes
- 10.11. The cfg! Macro
- 10.12. macro_rules!
- 10.13. Proc Macros
- 10.14. unsafe
- 10.15. static Variables
- 10.16. LazyLock
- 10.17. extern Blocks
- 10.18. union
- 10.19. The Never Type !
- 11. Advanced Standard Library Topics
- 11.1. AsRef<T> / AsMut<T>
- 11.2. Ordering and Sorting
- 11.3. HashMap<K, V>
- 11.4. HashSet<T>
- 11.5. A Brief Tour of Other Collections
- 11.6. std::env / std::process
- 11.7. std::path
- 11.8. String Methods
- 11.9. I/O: stdin and File Access
- 11.10. The Error trait
- 11.11. A Brief Introduction to thiserror / anyhow
- 11.12. catch_unwind
- 12. Async
- 12.1. Your First async Program
- 12.2. Why We Need async
- 12.3. async fn Returns a Future
- 12.4. async as an Effect
- 12.5. async Blocks
- 12.6. The Future trait and the Most Bare-bones Executor
- 12.7. Writing a Delay Future by Hand
- 12.8. Waiting for Delay with .await
- 12.9. Writing join by Hand
- 12.10. Waking the Executor with Threads and Wakers
- 12.11. spawn and the Ready Queue
- 12.12. spawn and JoinHandle
- 12.13. mio
- 12.14. Writing a Reactor by Hand
- 12.15. The State Machine behind async fn
- 12.16. Self-referential Futures
- 12.17. Why poll Needs Pin
- 12.18. Unpin
- 12.19. pin!
- 12.20. async Recursion
- 12.21. Back to Tokio
- 12.22. spawn_blocking
- 12.23. join!
- 12.24. Semaphore and Backpressure
- 12.25. mpsc
- 12.26. oneshot, watch, and broadcast
- 12.27. AsyncRead and AsyncWrite
- 12.28. select!
- 12.29. async Mutex, RwLock, and Notify
- 12.30. Stream
- 12.31. JoinSet and FuturesUnordered
- 12.32. Graceful Shutdown
- 12.33. Testing async Code
- 12.34. Runtimes Other Than Tokio
- 13. Appendix II
- 13.1. 'a: 'b
- 13.2. HRTB
- 13.3. Variance
- 13.4. PhantomData / PhantomPinned
- 13.5. GAT
- 13.6. async Closures
- 13.7. use Bounds