From 855f1ff3215e76d438783d8bdf743d6cb641ff89 Mon Sep 17 00:00:00 2001 From: Ruby Date: Thu, 6 Aug 2015 19:29:03 +0100 Subject: [PATCH 1/2] Explained asterisk on & and &mut reference --- src/doc/trpl/references-and-borrowing.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/doc/trpl/references-and-borrowing.md b/src/doc/trpl/references-and-borrowing.md index d1d3063138e7e..1709ac8f26bba 100644 --- a/src/doc/trpl/references-and-borrowing.md +++ b/src/doc/trpl/references-and-borrowing.md @@ -125,6 +125,10 @@ This will print `6`. We make `y` a mutable reference to `x`, then add one to the thing `y` points at. You’ll notice that `x` had to be marked `mut` as well, if it wasn’t, we couldn’t take a mutable borrow to an immutable value. +You'll also notice we added an asterisk in front of `y`, making it `*y`, +this is because y is an `&mut` reference. You'll also need to use them for +accessing and modifying `&` references as well. + Otherwise, `&mut` references are just like references. There _is_ a large difference between the two, and how they interact, though. You can tell something is fishy in the above example, because we need that extra scope, with From d3e089f08bd55fc5e663400f513f77e567636628 Mon Sep 17 00:00:00 2001 From: Ruby Date: Thu, 6 Aug 2015 19:55:53 +0100 Subject: [PATCH 2/2] fixed the few nits! --- src/doc/trpl/references-and-borrowing.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/doc/trpl/references-and-borrowing.md b/src/doc/trpl/references-and-borrowing.md index 1709ac8f26bba..a7a77539f7958 100644 --- a/src/doc/trpl/references-and-borrowing.md +++ b/src/doc/trpl/references-and-borrowing.md @@ -125,9 +125,9 @@ This will print `6`. We make `y` a mutable reference to `x`, then add one to the thing `y` points at. You’ll notice that `x` had to be marked `mut` as well, if it wasn’t, we couldn’t take a mutable borrow to an immutable value. -You'll also notice we added an asterisk in front of `y`, making it `*y`, -this is because y is an `&mut` reference. You'll also need to use them for -accessing and modifying `&` references as well. +You'll also notice we added an asterisk (`*`) in front of `y`, making it `*y`, +this is because `y` is an `&mut` reference. You'll also need to use them for +accessing the contents of a reference as well. Otherwise, `&mut` references are just like references. There _is_ a large difference between the two, and how they interact, though. You can tell