trait Foo {
fn f(&self);
}
trait Bar {
fn f(&self);
}
struct Baz;
impl Foo for Baz {
fn f(&self) { println!("Baz’s impl of Foo"); }
}
impl Bar for Baz {
fn f(&self) { println!("Baz’s impl of Bar"); }
}
let b = Baz;
如果我們試圖調(diào)用 b.f(),我們就會得到一個錯誤:
error: multiple applicable methods in scope [E0034]
b.f();
note: candidate #1 is defined in an impl of the trait `main::Foo` for the type`main::Baz`
fn f(&self) { println!("Baz’s impl of Foo"); }
note: candidate #2 is defined in an impl of the trait `main::Bar` for the type`main::Baz`
fn f(&self) { println!("Baz’s impl of Bar"); }
更多建議: