X-Git-Url: https://git.ralfj.de/rust-101.git/blobdiff_plain/7296568ff6faea20c9d34cd716fc82c8166df154..8592458fd3494ebce80727341663c7b0036e3ede:/src/part04.rs?ds=inline diff --git a/src/part04.rs b/src/part04.rs index fb3604e..21654cd 100644 --- a/src/part04.rs +++ b/src/part04.rs @@ -98,12 +98,12 @@ fn shared_ref_demo() { //@ that was created before calling `vec_min` remains valid. // ## Unique, mutable references - //@ There is a second way to borrow something, a second kind of reference: The *mutable reference*. //@ This is a reference that comes with the promise that nobody else has *any kind of access* to //@ the referee - in contrast to shared references, there is no aliasing with mutable references. -//@ It is thus always safe to perform mutation through such a reference. -//@ Because there cannot be another reference to the same data, we could also call it a *unique* reference, but that is not their official name. +//@ It is thus always safe to perform mutation through such a reference. Because there cannot be +//@ another reference to the same data, we could also call it a *unique* reference, but that is not +//@ their official name. //@ As an example, consider a function which increments every element of a vector by 1. //@ The type `&mut Vec` is the type of mutable references to `vec`. Because the reference @@ -121,7 +121,6 @@ fn mutable_ref_demo() { vec_inc(&mut v); /* println!("The first element is: {}", *first); */ /* BAD! */ } - //@ `&mut` is the operator to create a mutable reference. We have to mark `v` as mutable in order //@ to create such a reference: Even though we completely own `v`, Rust tries to protect us from //@ accidentally mutating things.