Book 1 · Lesson 1.7
Borrow checker deep dive
- Fix common borrow checker errors
- Explain mutable vs shared borrows
- Connect compile failures to safer services
Prerequisites: 1.6
The borrow checker is Rust’s static proof that references never outlive data or alias illegally.
| Borrow | Syntax | Rule |
|---|---|---|
| Shared | &T | Many readers OR one writer |
| Mutable | &mut T | Exclusive — no other borrows |
Scenario 1 of 3
let mut v = vec![1]; let r = &mut v; v.push(2);
Lifetimes (preview)
When references appear in structs or return types, lifetime annotations ('a) tell the compiler how long borrows remain valid. Analyzer SQLx queries often return rows tied to connection lifetime.
EM angle
Borrow errors in CI = cheaper than data races in prod.
Teach-back prompt
Why is &mut incompatible with another active & to the same value?
Annotate lifetimes (preview)
Lab complete — nice work.