concept borrowing in category rust

appears as: borrowing
Rust in Action

This is an excerpt from Manning's book Rust in Action.

The ampersand (&) prefix to haystack on line 5, e.g. &haystack, may look unfamiliar. The ampersand is acting as a unary operator that returns a reference to haystack. For any type T, the syntax &T returns a read-only reference to T. A useful quirk of references to arrays is that they enable you to iterate over references to the elements of the array with for loops. In Rust terminology, when we use &T we borrow T. A “borrowed” value outlives the scope that it is being used in. The concept of borrowing and its terminology are explained in detail during in chapter 4.

Borrow checking relies on three inter-related concepts: lifetimes, ownership and borrowing.