Rust TutorialLesson 21Free preview
Rust Borrowing
This lesson is part of Rust · All levels
Summary
This lesson discusses the mechanism of borrowing through reference in Rust. Instead of transferring ownership, the function can lend access to the data using the '&' symbol. Rust applies a strict rule: You can have multiple immutable references, OR only one mutable reference at a time.
Key points
- References are made using the ampersand symbol '&' without transferring ownership
- By default, the reference is read-only (immutable reference)
- The mutable reference is made with '&mut' to change the borrowed data
- The rule of thumb: at one time, there can be multiple "&T" OR exactly one "&mut T"
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.