Skip to content

Commit 3610c73

Browse files
committed
Rollup merge of rust-lang#28225 - jackwilsonv:patch-3, r=steveklabnik
r? @steveklabnik
2 parents 6b36e92 + f44fbf0 commit 3610c73

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/doc/trpl/method-syntax.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ can be awkward. Consider this code:
77
baz(bar(foo));
88
```
99

10-
We would read this left-to right, and so we see ‘baz bar foo’. But this isn’t the
10+
We would read this left-to-right, and so we see ‘baz bar foo’. But this isn’t the
1111
order that the functions would get called in, that’s inside-out: ‘foo bar baz’.
1212
Wouldn’t it be nice if we could do this instead?
1313

@@ -45,17 +45,17 @@ This will print `12.566371`.
4545

4646

4747

48-
We’ve made a struct that represents a circle. We then write an `impl` block,
48+
We’ve made a `struct` that represents a circle. We then write an `impl` block,
4949
and inside it, define a method, `area`.
5050

51-
Methods take a special first parameter, of which there are three variants:
51+
Methods take a special first parameter, of which there are three variants:
5252
`self`, `&self`, and `&mut self`. You can think of this first parameter as
5353
being the `foo` in `foo.bar()`. The three variants correspond to the three
5454
kinds of things `foo` could be: `self` if it’s just a value on the stack,
5555
`&self` if it’s a reference, and `&mut self` if it’s a mutable reference.
5656
Because we took the `&self` parameter to `area`, we can use it just like any
5757
other parameter. Because we know it’s a `Circle`, we can access the `radius`
58-
just like we would with any other struct.
58+
just like we would with any other `struct`.
5959

6060
We should default to using `&self`, as you should prefer borrowing over taking
6161
ownership, as well as taking immutable references over mutable ones. Here’s an
@@ -120,12 +120,12 @@ Check the return type:
120120
```rust
121121
# struct Circle;
122122
# impl Circle {
123-
fn grow(&self) -> Circle {
123+
fn grow(&self, increment: f64) -> Circle {
124124
# Circle } }
125125
```
126126

127127
We just say we’re returning a `Circle`. With this method, we can grow a new
128-
circle to any arbitrary size.
128+
`Circle` to any arbitrary size.
129129

130130
# Associated functions
131131

@@ -161,7 +161,7 @@ methods’.
161161

162162
# Builder Pattern
163163

164-
Let’s say that we want our users to be able to create Circles, but we will
164+
Let’s say that we want our users to be able to create `Circle`s, but we will
165165
allow them to only set the properties they care about. Otherwise, the `x`
166166
and `y` attributes will be `0.0`, and the `radius` will be `1.0`. Rust doesn’t
167167
have method overloading, named arguments, or variable arguments. We employ
@@ -224,7 +224,7 @@ fn main() {
224224
}
225225
```
226226

227-
What we’ve done here is make another struct, `CircleBuilder`. We’ve defined our
227+
What we’ve done here is make another `struct`, `CircleBuilder`. We’ve defined our
228228
builder methods on it. We’ve also defined our `area()` method on `Circle`. We
229229
also made one more method on `CircleBuilder`: `finalize()`. This method creates
230230
our final `Circle` from the builder. Now, we’ve used the type system to enforce

0 commit comments

Comments
 (0)