Lending
There's one more way we can send information to a different scope and that is by lending. When we move a data value, the receiving scope becomes the value's new owner. When we copy a data value, the receiving scope owns the duplicate it received, and the sending scope retains ownership of the original. When we lend a data value, things can get more complicated, because the original scope retains ownership, but the receiving scope is still allowed to access the data.
The original scope still owns the data, which means that, when that scope ends, the data will go away. If some of the scope's contained data was still loaned to a different scope at that time, the program would likely crash and, since the Rust compiler hates potential ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access