Hi all,
I can't understand why in the following example, func3
is not compiling. I can understand why func2
doesn't but because of the trait bound on AB
, func3
should.
struct S(u8);
trait Lookup<T> {
fn foo(&self);
}
struct A;
struct B;
trait AB{}
impl AB for A{}
impl AB for B{}
impl Lookup<A> for S {
fn foo(&self) {
println!("foo A");
}
}
impl Lookup<B> for S {
fn foo(&self) {
println!("foo B");
}
}
impl S {
fn func1(&self, condition: bool) {
if condition {
Lookup::<A>::foo(self);
} else {
Lookup::<B>::foo(self);
}
}
fn func2<T>(&self, condition: bool) {
if condition {
Lookup::<T>::foo(self);
} else {
Lookup::<T>::foo(self);
}
}
fn func3<T: AB>(&self, condition: bool) {
if condition {
Lookup::<T>::foo(self);
} else {
Lookup::<T>::foo(self);
}
}
}
Any explanation welcome !
Thanks in advance.