The following code fails to compile because both X
and Y
have a function x()
.
X::f(&n)
doesn't work because n
is type Box<dyn Y>
.
How to call n.(Y::f)()
in this situation?
trait X {
fn f(&self) {
println!("x")
}
}
trait Y: X {
fn f(&self) {
println!("y")
}
}
impl X for u32 {}
impl Y for u32 {}
fn main() {
let n: Box<dyn Y> = Box::new(1);
println!("{:?}", n.f());
}