X-Git-Url: https://git.ralfj.de/rust-101.git/blobdiff_plain/4b75a1808a0ee75383f81659f6262fefc7047a09..b89eed2cb450e67dd00102d1018adbb9a0cb1cae:/src/part06.rs diff --git a/src/part06.rs b/src/part06.rs index 8161d2d..5be00aa 100644 --- a/src/part06.rs +++ b/src/part06.rs @@ -137,7 +137,7 @@ fn rust_foo(mut v: Vec) -> i32 { //@ When analyzing the code of `rust_foo`, Rust has to assign a lifetime to `first`. It will choose the scope //@ where `first` is valid, which is the entire rest of the function. Because `head` ties the lifetime of its //@ argument and return value together, this means that `&v` also has to borrow `v` for the entire duration of -//@ the function. So when we try to borrow `v` mutable for `push`, Rust complains that the two borrows (the one +//@ the function `rust_foo`. So when we try to borrow `v` as mutable for `push`, Rust complains that the two borrows (the one //@ for `head`, and the one for `push`) overlap. Lucky us! Rust caught our mistake and made sure we don't crash the program. //@ //@ So, to sum this up: Lifetimes enable Rust to reason about *how long* a pointer has been borrowed. We can thus @@ -145,6 +145,6 @@ fn rust_foo(mut v: Vec) -> i32 { //@ are used correctly, *while looking only at the function type*. At no point in our analysis of `rust_foo` did //@ we have to look *into* `head`. That's, of course, crucial if we want to separate library code from application code. //@ Most of the time, we don't have to explicitly add lifetimes to function types. This is thanks to *lifetimes elision*, -//@ where Rust will automatically insert lifetimes we did not specify, following some [simple, well-documented rules](http://doc.rust-lang.org/stable/book/lifetimes.html#lifetime-elision). +//@ where Rust will automatically insert lifetimes we did not specify, following some [simple, well-documented rules](https://doc.rust-lang.org/stable/book/lifetimes.html#lifetime-elision). -//@ [index](main.html) | [previous](part05.html) | [next](part07.html) +//@ [index](main.html) | [previous](part05.html) | [raw source](https://www.ralfj.de/git/rust-101.git/blob_plain/HEAD:/workspace/src/part06.rs) | [next](part07.html)