-
Book Overview & Buying
-
Table Of Contents
Rust for C++ Developers
By :
A model that only allows a single owner at any given time could seem a bit restrictive, especially when it relies on shallow and deep data copies using moves and clones, respectively. Often, when passing parameters to functions, and sometimes even when storing data in structures, we just need to use a reference instead of passing the entire structure around. Fortunately, Rust allows us to produce a reference to a piece of data by borrowing it from the owner. Throughout this section, we'll refer to the act of creating a reference as a "borrow," and use "reference" to refer to the value produced by borrowing.
As with ownership, Rust puts additional rules on the use of references to make it easier to guarantee correct program behavior. The part of the compiler that enforces these rules is often referred to as the borrow checker.
An immutable reference is one that cannot cause the borrowed data to change, regardless...