Skip to content

Commit

Permalink
Rollup merge of rust-lang#29873 - steveklabnik:gh29493, r=nikomatsakis
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Nov 17, 2015
2 parents 98b18f5 + 9e25a1c commit ff2f745
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/doc/trpl/ufcs.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,28 @@ Here’s an example of using the longer form.

```rust
trait Foo {
fn clone(&self);
fn foo() -> i32;
}

#[derive(Clone)]
struct Bar;

impl Foo for Bar {
fn clone(&self) {
println!("Making a clone of Bar");
impl Bar {
fn foo() -> i32 {
20
}
}

<Bar as Clone>::clone(self);
impl Foo for Bar {
fn foo() -> i32 {
10
}
}

fn main() {
assert_eq!(10, <Bar as Foo>::foo());
assert_eq!(20, Bar::foo());
}
```

This will call the `Clone` trait’s `clone()` method, rather than `Foo`’s.
Using the angle bracket syntax lets you call the trait method instead of the
inherent one.

0 comments on commit ff2f745

Please sign in to comment.