Rollup merge of #29571 - steveklabnik:gh29322, r=apasel422

Fixes #29322
This commit is contained in:
Steve Klabnik 2015-11-05 12:43:03 +01:00
commit f04e77d598
1 changed files with 29 additions and 2 deletions

View File

@ -43,8 +43,6 @@ fn main() {
This will print `12.566371`.
Weve 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 youd 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