liveBook · Manning

Ownership transfer

As explained in Learn Rust in a Month of Lunches

Ownership transfer is the movement of a value's controlling ownership from one binding or function to another.

Ownership transfer moves control of a value from one binding or function to another. After the transfer, the new owner can use the value, while the previous owner cannot ask for it back. section 2.10

Handing over a computer

Imagine that you own a computer and give it to a coworker. The coworker becomes the owner and may declare it mutable, using it however they want. You cannot simply take ownership back. section 2.10

This differs from immutable references, which let someone look at a value, and mutable references, which allow temporary use under stricter limits. Copy types are different again: their values are cheap to copy, like office pens or paperclips. section 2.10

How Learn Rust in a Month of Lunches covers it

How deep it goes
Explains transfer through an analogy and contrasts it with references and Copy types, but does not show transfer syntax or compiler feedback.
Examples
Uses a coworker taking ownership of a computer and compares Copy types with pens, paperclips, and sticky notes.
What you can do after
Evaluate whether an example represents transferred ownership, borrowing through references, or inexpensive copying.
How it connects
Connects ownership transfer with memory, immutable references, mutable references, Copy types, primitive types, and String.

Also explained in

Compare how 3 books explain ownership transfer →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Rust in a Month of Lunches. The section links point to the parts of the book it draws on.