Skip to content

Commit 386a144

Browse files
committed
book: 'x' is already taken, so use something else
1 parent c897ac0 commit 386a144

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/doc/trpl/method-syntax.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ Functions are great, but if you want to call a bunch of them on some data, it
44
can be awkward. Consider this code:
55

66
```{rust,ignore}
7-
baz(bar(foo(x)));
7+
baz(bar(foo)));
88
```
99

1010
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

1414
```{rust,ignore}
15-
x.foo().bar().baz();
15+
foo.bar().baz();
1616
```
1717

1818
Luckily, as you may have guessed with the leading question, you can! Rust provides
@@ -47,8 +47,8 @@ This will print `12.566371`.
4747
We've made a struct that represents a circle. We then write an `impl` block,
4848
and inside it, define a method, `area`. Methods take a special first
4949
parameter, of which there are three variants: `self`, `&self`, and `&mut self`.
50-
You can think of this first parameter as being the `x` in `x.foo()`. The three
51-
variants correspond to the three kinds of thing `x` could be: `self` if it's
50+
You can think of this first parameter as being the `foo` in `foo.bar()`. The three
51+
variants correspond to the three kinds of things `foo` could be: `self` if it's
5252
just a value on the stack, `&self` if it's a reference, and `&mut self` if it's
5353
a mutable reference. We should default to using `&self`, as you should prefer
5454
borrowing over taking ownership, as well as taking immutable references

0 commit comments

Comments
 (0)