01
Ownership Rules
How visible in the type a value's location is, how the single-owner rule forces a move, how borrowing grants access without transferring ownership, how a slice views data without taking ownership, and what the checker that tests all of this at compile time actually guarantees.
- 01 Stack and Heap A fourteen-value measurement core runs and places every value's life into one of four classes — scope end, where it was moved, an explicit call, together with its container; the result is fixed at 6/3/1/4. It measures that values ending at scope end finish in the exact reverse of their declaration order, and that a heap-allocated value drops into the same ledger.
- 02 Ownership and Moves Moving a value into a function, into an inner scope, and into a struct field all fall into the same class (where it was moved), and in all three the value ends exactly once; that the old binding cannot be used after a move is a rule the compiler tests at compile time, while the new owner can use the value without any problem.
- 03 Borrowing A value can be read and written through a reference without ever giving up ownership: while the borrow lasts no record forms in the ledger, and once the borrow's scope closes the value is still accessible in its owner. A shared and a mutable reference exclude each other; a reference's scope always has to stay inside its source's scope.
- 04 Slices A slice views a specific range of a string or a growable array without taking ownership: the slice gets used, the slice ends, but the source never ends. A slice's length derives from the source, and an empty slice is valid; the source cannot be changed while the slice lives, and a change goes through without a problem once the slice ends.
- 05 The Borrow Checker The borrow checker tests a value's ownership and borrowing rules at compile time; three rejection examples (a live borrow during a move, mutating while reading, returning a reference to a local owner) are always described in prose, with an accepted solution run alongside each. Two different solutions doing the same job can produce the same ledger record; code that follows the borrowing rules can still give a wrong result — the checker guarantees not correctness, only ownership discipline.