programmers have typically used in C and C++ to make their code
comprehensible.
+[ Borrowing example slide ] https://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html#mutable-references
+
But in Rust the ownership is known to the language, and the rules
surrounding ownership are enforced by the compiler. When an object
ceases to have an owner, it is freed.
This ownership system is used not only for dynamically allocated
objects, but for local variables, and statically allocated objects.
-[ Borrowing example slide ] https://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html#mutable-references
+[ dangling reference error example https://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html#dangling-references ]
To allow an object to be accessed other than through owner, Rust
formalises the notion of borrowing. An object can be borrowed by
writing the ampersand, giving a reference. The compiler checks that
the object will outlive the reference.
-[ dangling reference error example https://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html#dangling-references ]
+[ Borrowing example slide with mut missing ] ABOVE https://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html#mutable-references
Borrows (that is, references) come in two kinds: mutable and
immutable. You can have many immutable references at once. A mutable
reference permits modification, and provides exclusive access.
-[ Borrowing example slide with mut missing ] ABOVE https://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html#mutable-references
-
That's what the `mut' is doing in that example. If you leave it out
the compiler complains. This is the Rust `borrow checker' that you
have may have heard about: the part of the compiler which enforces the