diff options
| author | bors <bors@rust-lang.org> | 2015-11-05 12:49:44 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-11-05 12:49:44 +0000 |
| commit | 2509948b3e4413d757424d6f544db1db2c05481a (patch) | |
| tree | 80dd1e8e15083479f5113294df43afea5311a787 /src/doc/trpl/method-syntax.md | |
| parent | 792a9f12cff83186a5426bc6e713fbc11261a4b1 (diff) | |
| parent | 05cbfa478c8cbc79a6baac714da4f3d5d77c6919 (diff) | |
Auto merge of #29610 - steveklabnik:rollup, r=steveklabnik
- Successful merges: #29416, #29537, #29538, #29539, #29567, #29568, #29571, #29579 - Failed merges:
Diffstat (limited to 'src/doc/trpl/method-syntax.md')
| -rw-r--r-- | src/doc/trpl/method-syntax.md | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/src/doc/trpl/method-syntax.md b/src/doc/trpl/method-syntax.md index d31d8232470..41c134b29f3 100644 --- a/src/doc/trpl/method-syntax.md +++ b/src/doc/trpl/method-syntax.md @@ -43,8 +43,6 @@ fn main() { 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`. @@ -83,6 +81,35 @@ impl Circle { } ``` +You can use as many `impl` blocks as you’d like. The previous example could +have also been written like this: + +```rust +struct Circle { + x: f64, + y: f64, + radius: f64, +} + +impl Circle { + fn reference(&self) { + println!("taking self by reference!"); + } +} + +impl Circle { + fn mutable_reference(&mut self) { + println!("taking self by mutable reference!"); + } +} + +impl Circle { + fn takes_ownership(self) { + println!("taking ownership of self!"); + } +} +``` + # Chaining method calls So, now we know how to call a method, such as `foo.bar()`. But what about our |
