liveBook · Manning

Borrowing

As explained in Rust Servers, Services, and Apps

Borrowing is Rust's mechanism for granting temporary access to a value without transferring its ownership.

Borrowing grants temporary access to a value without transferring ownership. Rust uses references and compile-time checking to keep borrowed access within the value’s lifetime. section 1.2.2

Borrowing uses two reference forms with exclusive mutation rules:

  • Use `&` to create a reference to a value. section 1.2.2
  • Use `&T` for immutable sharing without mutation. section 1.2.2
  • Use `&mut T` for mutation, excluding all other mutable or immutable borrows of that object. section 1.2.2
  • The borrow checker ensures references do not outlive the values they borrow, preventing invalid memory access at compile time. section 1.2.2

How Rust Servers, Services, and Apps covers it

How deep it goes
Defines immutable and mutable references and compiler rules, but does not develop implementation examples or lifetime syntax.
Examples
Uses `&T` for shared access and `&mut T` for exclusive mutation.
What it assumes
Assumes ownership concepts while teaching references, temporary access, and mutable-borrow exclusivity.
What you can do after
Evaluate/understand how Rust permits temporary access without ownership transfer or invalid memory access.
How it connects
Connects borrowing to ownership, references, the borrow checker, lifetimes, memory safety, and thread safety.

Also explained in

Compare how 3 books explain borrowing →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Rust Servers, Services, and Apps. The section links point to the parts of the book it draws on.