Introduction
Practical suggestions for building intuition around borrow errors
1.
Sectional introduction
2.
Keep at it and participate in the community
3.
Prefer ownership over long-lived references
4.
Don't hide lifetimes
5.
Understand elision and get a feel for when to name lifetimes
6.
Get a feel for variance, references, and reborrows
❱
6.1.
The seed of a mental model
6.2.
Reference types
6.3.
Lifetime bounds
6.4.
Reference lifetimes
6.5.
Copy and reborrows
6.6.
Nested borrows and invariance
6.7.
Invariance elsewhere
6.8.
Non-references
7.
Get a feel for borrow-returning methods
❱
7.1.
When not to name lifetimes
7.2.
Bound-related lifetimes "infect" each other
7.3.
&mut inputs don't "downgrade" to &
7.4.
async and returning impl Trait
8.
Understand function lifetime parameters
9.
Understand borrows within a function
10.
Learn some pitfalls and antipatterns
❱
10.1.
dyn Trait lifetimes and Box<dyn Trait>
10.2.
Conditional return of a borrow
10.3.
Borrowing something forever
10.4.
&'a mut self and Self aliasing more generally
10.5.
Avoid self-referential structs
10.6.
&'a Struct<'a> and covariance
11.
Scrutinize compiler advice
❱
11.1.
Advice to change function signature when aliases are involved
11.2.
Advice to add bound which implies lifetime equality
11.3.
Advice to add a static bound
12.
Illustrative examples
❱
12.1.
Mutable slice iterator
13.
Circle back
Miscellanea
14.
Sectional introduction
15.
Slice layout
16.
Default parameter mechanics
A tour of dyn Trait
17.
Sectional introduction
18.
dyn Trait overview
19.
dyn Trait implementations
20.
dyn Trait coercions
21.
dyn safety (object safety)
22.
dyn Trait lifetimes
❱
22.1.
Variance
22.2.
Higher-ranked types
22.3.
Elision rules
❱
22.3.1.
Basic guidelines
22.3.2.
Advanced guidelines
22.3.3.
Trait bound interactions
22.3.4.
Citations
23.
dyn Trait vs. alternatives
24.
dyn Trait examples
❱
24.1.
Combining traits
24.2.
impl Trait for Box<dyn Trait>
24.3.
Cloneable Box<dyn Trait>
24.4.
dyn PartialEq
24.5.
Generalizing borrows
24.6.
Erased traits
24.7.
Hashable Box<dyn Trait>
24.8.
dyn Any examples
25.
dyn Any
Light
Rust
Coal
Navy
Ayu
Learning Rust
Miscellanea
This section collects relatively small and self-contained tutorials and other tidbits.