Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mention multiple impl blocks in TRPL #29571

Merged
merged 1 commit into from
Nov 5, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions src/doc/trpl/method-syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand Down Expand Up @@ -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
Expand Down