@@ -6,7 +6,7 @@ become quite acquainted. Ownership is how Rust achieves its largest goal,
66memory safety. There are a few distinct concepts, each with its own
77chapter:
88
9- * ownership, which you’re reading now.
9+ * ownership, which you’re reading now
1010* [ borrowing] [ borrowing ] , and their associated feature ‘references’
1111* [ lifetimes] [ lifetimes ] , an advanced concept of borrowing
1212
@@ -23,7 +23,7 @@ Before we get to the details, two important notes about the ownership system.
2323Rust has a focus on safety and speed. It accomplishes these goals through many
2424‘zero-cost abstractions’, which means that in Rust, abstractions cost as little
2525as possible in order to make them work. The ownership system is a prime example
26- of a zero cost abstraction. All of the analysis we’ll talk about in this guide
26+ of a zero- cost abstraction. All of the analysis we’ll talk about in this guide
2727is _ done at compile time_ . You do not pay any run-time cost for any of these
2828features.
2929
@@ -41,7 +41,7 @@ With that in mind, let’s learn about ownership.
4141
4242# Ownership
4343
44- [ ` Variable bindings ` ] [ bindings ] have a property in Rust: they ‘have ownership’
44+ [ Variable bindings] [ bindings ] have a property in Rust: they ‘have ownership’
4545of what they’re bound to. This means that when a binding goes out of scope, the
4646resource that they’re bound to are freed. For example:
4747
@@ -106,8 +106,8 @@ take(v);
106106println!("v[0] is: {}", v[0]);
107107```
108108
109- Same error: “ use of moved value.” When we transfer ownership to something else,
110- we say that we’ve ‘moved’ the thing we refer to. You don’t need some sort of
109+ Same error: ‘ use of moved value’. When we transfer ownership to something else,
110+ we say that we’ve ‘moved’ the thing we refer to. You don’t need any sort of
111111special annotation here, it’s the default thing that Rust does.
112112
113113## The details
@@ -121,19 +121,19 @@ let v = vec![1, 2, 3];
121121let v2 = v ;
122122```
123123
124- The first line creates some data for the vector on the [ stack ] [ sh ] , ` v ` . The
125- vector’s data, however, is stored on the [ heap ] [ sh ] , and so it contains a
126- pointer to that data . When we move ` v ` to ` v2 ` , it creates a copy of that pointer ,
127- for ` v2 ` . Which would mean two pointers to the contents of the vector on the
128- heap. That would be a problem: it would violate Rust’s safety guarantees by
129- introducing a data race. Therefore, Rust forbids using ` v ` after we’ve done the
130- move.
124+ The first line allocates memory for the vector object , ` v ` , and for the data it
125+ contains. The vector object is stored on the [ stack ] [ sh ] and contains a pointer
126+ to the content ( ` [1, 2, 3] ` ) stored on the [ heap ] [ sh ] . When we move ` v ` to ` v2 ` ,
127+ it creates a copy of that pointer, for ` v2 ` . Which means that there would be two
128+ pointers to the content of the vector on the heap. It would violate Rust’s
129+ safety guarantees by introducing a data race. Therefore, Rust forbids using ` v `
130+ after we’ve done the move.
131131
132132[ sh ] : the-stack-and-the-heap.html
133133
134134It’s also important to note that optimizations may remove the actual copy of
135- the bytes, depending on circumstances. So it may not be as inefficient as it
136- initially seems.
135+ the bytes on the stack , depending on circumstances. So it may not be as
136+ inefficient as it initially seems.
137137
138138## ` Copy ` types
139139
0 commit comments