Borrowing
A borrow is how you use a value without taking it. The rules are one sentence long — many readers, or one writer, never both — and the errors they produce are what the borrow checker is famous for.
These are the articles to read before you hit the error, not after.
Articles
Section titled “Articles”- How to borrow a valuethe & that stops a move
- What is the difference between & and &mut?read many, or write one, never both
- What are the rules of borrowing?one paragraph you can hold in your head
- Why does Rust allow many immutable borrows but only one mutable?iterators and aliasing make it concrete
- What is the borrow checker?the pass that produces those errors
- What is reborrowing?why &mut does not move as often as you expect
- How long does a borrow last?non-lexical lifetimes, and the scope you thought it had
- How to borrow one field of a structdisjoint borrows, and the method call that borrows all of it
- When should you take a reference instead of cloning?the signature that decides for you
- How to end a borrow earlya scope, a drop, and the reference that outlives it
- What is a slice, and why is it a borrow?&[T] as a borrowed window onto someone else’s data
- How to change what a mutable reference points at*r = other, and the binding that is not mut