Skip to content

Commit 0c93e72

Browse files
committed
Mention multiple impl blocks in TRPL
Fixes #29322
1 parent a216e84 commit 0c93e72

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

src/doc/trpl/method-syntax.md

+29-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ fn main() {
4343

4444
This will print `12.566371`.
4545

46-
47-
4846
We’ve made a `struct` that represents a circle. We then write an `impl` block,
4947
and 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

88115
So, now we know how to call a method, such as `foo.bar()`. But what about our

0 commit comments

Comments
 (0)