bck-lifetimes.ps: bck-err.txt.eps
macros.ps: serde-example.txt.eps macro-rules-example.txt.eps
borrow-mut.ps: borrow-mut-example.txt.eps
-dangling.ps: dangling.txt.eps
+dangling.ps: dangling.txt.eps dangling-err.txt.eps
%.eps: %.fig
iconv <$< >$@.1 -f UTF-8 -t ISO-8859-1
--- /dev/null
+error[E0106]: missing lifetime specifier
+ --> main.rs:5:16
+ |
+5 | fn dangle() -> &String {
+ | ^ expected lifetime parameter
+ |
+ = help: this function's return type contains a borrowed
+ value, but there is no value for it to be borrowed from
+ = help: consider giving it a 'static lifetime
1200 2
2 5 0 1 0 -1 60 -1 -1 0.000 0 0 -1 0 0 5
0 dangling.txt.eps
- -1170 -2250 10593 -2250 10593 3993 -1170 3993 -1170 -2250
+ -1170 -2250 10593 -2250 10593 1625 -1170 1625 -1170 -2250
+2 5 0 1 0 -1 60 -1 -1 0.000 0 0 -1 0 0 5
+ 0 dangling-err.txt.eps
+ -1170 2155 10593 2155 10593 5080 -1170 5080 -1170 2155
+2 1 0 2 0 7 50 -1 -1 0.000 0 0 7 0 0 2
+ -1260 1890 10800 1890
let s = String::from("hello");
&s
}
-
-
-error[E0106]: missing lifetime specifier
- --> main.rs:5:16
- |
-5 | fn dangle() -> &String {
- | ^ expected lifetime parameter
- |
- = help: this function's return type contains a borrowed
- value, but there is no value for it to be borrowed from
- = help: consider giving it a 'static lifetime
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