liveBook · Manning

Ownership

As explained in Rust Servers, Services, and Apps

An ownership model assigns each value a responsible owner and determines when that value may be accessed or destroyed.

Ownership gives every value one responsible owner, makes resource management explicit, and destroys the value when that owner leaves scope. This provides memory safety without garbage collection while retaining control over memory layout. section 1.2.2

Apply the model through three related rules:

  • Moving a value to another owner prevents the original owner from using it. section 1.2.2
  • Borrowing grants temporary access through references, without transferring ownership. section 1.2.2
  • Immutable references (&T) permit sharing without mutation; mutable references (&mut T) permit mutation without other simultaneous borrows. section 1.2.2

Scope and borrowing

A value is automatically destroyed when its owner goes out of scope. A borrowed reference must not outlive the value, and the borrow checker enforces these constraints at compile time. section 1.2.2

How Rust Servers, Services, and Apps covers it

How deep it goes
Explains ownership transfer, scope-based destruction, reference types, and borrow-checking constraints, without implementation internals.
Examples
Uses ownership transfer, scope exit, immutable references, and mutable references as concrete rule examples.
What it assumes
Contrasts ownership with garbage collection and manual memory management while assuming familiarity with those approaches.
What you can do after
Apply Rust ownership and borrowing rules while understanding the compiler guarantees against invalid memory access.
How it connects
Connects ownership to borrowing, references, RAII, smart pointers, garbage collection, and memory safety.

Also explained in

Compare how 6 books explain ownership →

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.