]> git.lizzy.rs Git - rust.git/commitdiff
Mention multiple impl blocks in TRPL
authorSteve Klabnik <steve@steveklabnik.com>
Wed, 4 Nov 2015 09:35:09 +0000 (10:35 +0100)
committerSteve Klabnik <steve@steveklabnik.com>
Wed, 4 Nov 2015 09:35:09 +0000 (10:35 +0100)
Fixes #29322

src/doc/trpl/method-syntax.md

index d31d82324708243b887dd6d355f058f6e67f09a8..41c134b29f3d18109ba3089cd941ce6072c979d9 100644 (file)
@@ -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