@@ -112,18 +112,19 @@ In the previous example, the value `on_the_stack` was defined like so:
112
112
let on_the_stack: Point = Point {x: 3.0, y: 4.0};
113
113
~~~
114
114
115
- This results in a by-value variable. As a consequence, we had to
116
- explicitly take the address of ` on_the_stack ` to get a borrowed
117
- pointer. Sometimes however it is more convenient to move the &
118
- operator into the definition of ` on_the_stack ` :
115
+ This declaration means that code can only pass ` Point ` by value to other
116
+ functions. As a consequence, we had to explicitly take the address of
117
+ ` on_the_stack ` to get a borrowed pointer. Sometimes however it is more
118
+ convenient to move the & operator into the definition of ` on_the_stack ` :
119
119
120
120
~~~
121
121
# struct Point {x: float, y: float}
122
122
let on_the_stack2: &Point = &Point {x: 3.0, y: 4.0};
123
123
~~~
124
124
125
125
Applying ` & ` to an rvalue (non-assignable location) is just a convenient
126
- shorthand for creating a temporary and taking its address:
126
+ shorthand for creating a temporary and taking its address. A more verbose
127
+ way to write the same code is:
127
128
128
129
~~~
129
130
# struct Point {x: float, y: float}
@@ -134,7 +135,7 @@ let on_the_stack2 : &Point = &tmp;
134
135
# Taking the address of fields
135
136
136
137
As in C, the ` & ` operator is not limited to taking the address of
137
- local variables. It can also be used to take the address of fields or
138
+ local variables. It can also take the address of fields or
138
139
individual array elements. For example, consider this type definition
139
140
for ` rectangle ` :
140
141
@@ -144,7 +145,7 @@ struct Size {w: float, h: float} // as before
144
145
struct Rectangle {origin: Point, size: Size}
145
146
~~~
146
147
147
- Now again I can define rectangles in a few different ways:
148
+ Now, as before, we can define rectangles in a few different ways:
148
149
149
150
~~~
150
151
# struct Point {x: float, y: float}
@@ -158,8 +159,8 @@ let rect_unique = ~Rectangle {origin: Point {x: 5f, y: 6f},
158
159
size: Size {w: 3f, h: 4f}};
159
160
~~~
160
161
161
- In each case I can use the ` & ` operator to extact out individual
162
- subcomponents . For example, I could write:
162
+ In each case, we can extract out individual subcomponents with the ` & `
163
+ operator . For example, I could write:
163
164
164
165
~~~
165
166
# struct Point {x: float, y: float} // as before
@@ -173,7 +174,7 @@ compute_distance(&rect_stack.origin, &rect_managed.origin);
173
174
~~~
174
175
175
176
which would borrow the field ` origin ` from the rectangle on the stack
176
- from the managed box and then compute the distance between them.
177
+ as well as from the managed box, and then compute the distance between them.
177
178
178
179
# Borrowing managed boxes and rooting
179
180
0 commit comments