File tree Expand file tree Collapse file tree 1 file changed +29
-2
lines changed
Expand file tree Collapse file tree 1 file changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -43,8 +43,6 @@ fn main() {
4343
4444This will print ` 12.566371 ` .
4545
46-
47-
4846We’ve made a ` struct ` that represents a circle. We then write an ` impl ` block,
4947and inside it, define a method, ` area ` .
5048
@@ -83,6 +81,35 @@ impl Circle {
8381}
8482```
8583
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+
86113# Chaining method calls
87114
88115So, 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