diff options
| author | Manish Goregaokar <manishsmail@gmail.com> | 2015-04-11 19:06:01 +0530 |
|---|---|---|
| committer | Manish Goregaokar <manishsmail@gmail.com> | 2015-04-11 19:06:01 +0530 |
| commit | 859c5ed4d64ddcc1d2ca03daeab9e9a0a0b81eb8 (patch) | |
| tree | 4325daaeaff905dc8d3c1bcc13e13ee9dc778841 | |
| parent | aa5eb33b9f330b6beec828838a2e755fbe303869 (diff) | |
| parent | 386a144e51d0b162928f95c4474c67944d7ebacb (diff) | |
| download | rust-859c5ed4d64ddcc1d2ca03daeab9e9a0a0b81eb8.tar.gz rust-859c5ed4d64ddcc1d2ca03daeab9e9a0a0b81eb8.zip | |
Rollup merge of #24309 - tshepang:doc-avoid-x-confusion, r=Manishearth
| -rw-r--r-- | src/doc/trpl/method-syntax.md | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/doc/trpl/method-syntax.md b/src/doc/trpl/method-syntax.md index f6eacd0a842..ae83a930a18 100644 --- a/src/doc/trpl/method-syntax.md +++ b/src/doc/trpl/method-syntax.md @@ -4,7 +4,7 @@ Functions are great, but if you want to call a bunch of them on some data, it can be awkward. Consider this code: ```{rust,ignore} -baz(bar(foo(x))); +baz(bar(foo))); ``` We would read this left-to right, and so we see "baz bar foo." But this isn't the @@ -12,7 +12,7 @@ order that the functions would get called in, that's inside-out: "foo bar baz." Wouldn't it be nice if we could do this instead? ```{rust,ignore} -x.foo().bar().baz(); +foo.bar().baz(); ``` Luckily, as you may have guessed with the leading question, you can! Rust provides @@ -47,8 +47,8 @@ This will print `12.566371`. We've made a struct that represents a circle. We then write an `impl` block, and inside it, define a method, `area`. Methods take a special first parameter, of which there are three variants: `self`, `&self`, and `&mut self`. -You can think of this first parameter as being the `x` in `x.foo()`. The three -variants correspond to the three kinds of thing `x` could be: `self` if it's +You can think of this first parameter as being the `foo` in `foo.bar()`. The three +variants correspond to the three kinds of things `foo` could be: `self` if it's just a value on the stack, `&self` if it's a reference, and `&mut self` if it's a mutable reference. We should default to using `&self`, as you should prefer borrowing over taking ownership, as well as taking immutable references |
