File tree 1 file changed +29
-2
lines changed
1 file changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -43,8 +43,6 @@ fn main() {
43
43
44
44
This will print ` 12.566371 ` .
45
45
46
-
47
-
48
46
We’ve made a ` struct ` that represents a circle. We then write an ` impl ` block,
49
47
and inside it, define a method, ` area ` .
50
48
@@ -83,6 +81,35 @@ impl Circle {
83
81
}
84
82
```
85
83
84
+ You can use as many ` impl ` blocks as you’d like. The previous example could
85
+ have also been written like this:
86
+
87
+ ``` rust
88
+ struct Circle {
89
+ x : f64 ,
90
+ y : f64 ,
91
+ radius : f64 ,
92
+ }
93
+
94
+ impl Circle {
95
+ fn reference (& self ) {
96
+ println! (" taking self by reference!" );
97
+ }
98
+ }
99
+
100
+ impl Circle {
101
+ fn mutable_reference (& mut self ) {
102
+ println! (" taking self by mutable reference!" );
103
+ }
104
+ }
105
+
106
+ impl Circle {
107
+ fn takes_ownership (self ) {
108
+ println! (" taking ownership of self!" );
109
+ }
110
+ }
111
+ ```
112
+
86
113
# Chaining method calls
87
114
88
115
So, now we know how to call a method, such as ` foo.bar() ` . But what about our
You can’t perform that action at this time.
0 commit comments