Improve UFCS example

Fixes #29493
This commit is contained in:
Steve Klabnik 2015-11-16 16:51:58 -05:00
parent 57c8a3e8b6
commit 9e25a1ccd3

View File

@ -109,19 +109,28 @@ Heres 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");
<Bar as Clone>::clone(self);
impl Bar {
fn foo() -> i32 {
20
}
}
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` traits `clone()` method, rather than `Foo`s.
Using the angle bracket syntax lets you call the trait method instead of the
inherent one.