Skip to content

Commit fd20065

Browse files
committed
Minor edits
1 parent 10a2ae4 commit fd20065

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

09_01_shared_references.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ A mutable reference can modify the underlying data where as the shared reference
55
We already saw an example of a shared reference in chapter 6 where we created a slice reference to data on the heap by prepending `[u8]` with the `&` symbol.
66

77
A reference is a kind of pointer.
8-
It points to some data elsewhere and "borrows" it instead of "owns" it.
8+
It points to some data elsewhere and "borrows" it instead of "owning" it.
99
What does this mean?
1010
Well let's see with an [example](https://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html#references-and-borrowing):
1111

@@ -46,6 +46,7 @@ It also mentions that the type, `String` does not implement the `Copy` trait.
4646
By default, any type that does not implement the `Copy` trait will get "moved" when passed as an argument.
4747
This means the variable that contains it will no longer be available within the scope of original function.
4848
It's "ownership" is now passed to the function being called, which in this case is `calculate_length`.
49+
4950
Why does Rust do this?
5051
Well this has to do with how Rust handles memory management internally.
5152
This way, it's always clear which variable "owns" data so that when that variable goes out of scope, the memory associated with it can be automatically freed.
@@ -55,7 +56,7 @@ So if we want to keep referring to the string after it has been passed to the `c
5556
The reference will "borrow" the value and won't actually "own" the underlying data.
5657
This means that when the reference goes out of scope and is no longer in use, the heap data and its owner will still remain.
5758

58-
We can create a reference by placing the `&` symbol in front and modifying the function argument type:
59+
We can create a reference by placing the `&` symbol in front of an identifier and modifying the function argument type:
5960

6061
```rust
6162
fn main() {

0 commit comments

Comments
 (0)