Skip to content

Commit f4a6b84

Browse files
committed
Copyedit sections 3 and 4 of the borrowed pointer tutorial
1 parent 0d8f447 commit f4a6b84

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

doc/tutorial-borrowed-ptr.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,18 +112,19 @@ In the previous example, the value `on_the_stack` was defined like so:
112112
let on_the_stack: Point = Point {x: 3.0, y: 4.0};
113113
~~~
114114

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`:
119119

120120
~~~
121121
# struct Point {x: float, y: float}
122122
let on_the_stack2: &Point = &Point {x: 3.0, y: 4.0};
123123
~~~
124124

125125
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:
127128

128129
~~~
129130
# struct Point {x: float, y: float}
@@ -134,7 +135,7 @@ let on_the_stack2 : &Point = &tmp;
134135
# Taking the address of fields
135136

136137
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
138139
individual array elements. For example, consider this type definition
139140
for `rectangle`:
140141

@@ -144,7 +145,7 @@ struct Size {w: float, h: float} // as before
144145
struct Rectangle {origin: Point, size: Size}
145146
~~~
146147

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:
148149

149150
~~~
150151
# struct Point {x: float, y: float}
@@ -158,8 +159,8 @@ let rect_unique = ~Rectangle {origin: Point {x: 5f, y: 6f},
158159
size: Size {w: 3f, h: 4f}};
159160
~~~
160161

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:
163164

164165
~~~
165166
# struct Point {x: float, y: float} // as before
@@ -173,7 +174,7 @@ compute_distance(&rect_stack.origin, &rect_managed.origin);
173174
~~~
174175

175176
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.
177178

178179
# Borrowing managed boxes and rooting
179180

0 commit comments

Comments
 (0)