Search⌘ K

Borrowing and Dereferencing Operators

Explore the use of borrowing and dereferencing operators in Rust to manage references efficiently. Understand shared versus mutable borrowing, how Rust uses pointers for memory safety, and how to modify data through dereferencing. This lesson builds foundational knowledge critical for safe and effective Rust programming.

Borrowing Operator #

Borrowing means to reference the original data binding or to share the data.

References are just like pointers in C.

Two variables are involved in a borrowing relationship when the referenced variable holds a value that the referencing variable borrows. The referencing variable simply points to the memory location of the referenced variable.

svg viewer

The following illustration shows that operand 1 borrows the value of operand 2 using ...