liveBook · Manning

Borrow checker

As explained in Rust Servers, Services, and Apps

The borrow checker is the Rust compiler component that statically verifies ownership, borrowing, and reference-lifetime rules.

The borrow checker is the Rust compiler component that enforces ownership and reference-lifetime rules at compile time. Each value has an owner, and the value is destroyed when that owner leaves scope. section 1.2.2

Borrowing applies temporary-access rules to references:

  • Immutable references (&T) permit sharing but not mutation. section 1.2.2
  • Mutable references (&mut T) permit mutation but cannot coexist with any other borrow of the same object. section 1.2.2
  • References cannot outlive the values they borrow, preventing invalid memory access. section 1.2.2

Shared versus exclusive access

A value may be shared through &T or changed through &mut T, but mutable access excludes both immutable and other mutable borrows. The compiler rejects violations before execution. section 1.2.2

How Rust Servers, Services, and Apps covers it

How deep it goes
Explains ownership, borrowing, reference lifetimes, and mutable-access exclusivity as compile-time rules.
Examples
Uses &T and &mut T to contrast shared access, mutation, and exclusive borrowing.
What you can do after
Evaluate Rust code for ownership and borrowing violations that could cause invalid memory access.
How it connects
Connects ownership with borrowing, references, RAII, smart pointers, memory safety, thread safety, and data races.

Also explained in

Compare how 4 books explain borrow checker →

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.