Think below code, impl
multiple times both for struct and traits:
mod m {
pub trait Foo {
fn xyzzy(&self) { println!("foo!"); }
}
pub trait Bar {
fn xyzzy(&self) { println!("bar!"); }
}
pub trait Quux: Foo+Bar {
fn xyzzy(&self) { println!("quux!"); }
}
pub struct X;
impl X {
pub fn xyzzy(&self) { println!("XXXXX self!"); }
}
impl Foo for X {}
impl Bar for X {}
impl Quux for X {}
}
use m::X;
fn main() {
let x = X;
x.xyzzy();
{
use m::Foo;
x.xyzzy(); // prints "foo!"
}
{
use m::Quux;
x.xyzzy(); // prints "quux!"
}
}
I want the result as below order:
XXXXX self!
foo!
quux!
But the result will be:
XXXXX self!
XXXXX self!
XXXXX self!
What's wrong here and how to implement the goal?