trait TraitA {
fn test_1(&self);
}
trait TraitB {
fn test_2(&self);
}
trait TraitAA {
fn test_3(&self);
}
trait TraitBB {
fn test_4(&self);
}
trait TraitCC {
fn test_5(&self);
}
struct Book;
impl TraitA for Book {
fn test_1(&self) {}
}
impl TraitB for Book {
fn test_2(&self) {}
}
struct Docs1;
impl TraitAA for Docs1 {
fn test_3(&self) {}
}
impl TraitBB for Docs1 {
fn test_4(&self) {}
}
impl TraitCC for Docs1 {
fn test_5(&self) {}
}
struct Docs2;
impl TraitAA for Docs2 {
fn test_3(&self) {}
}
impl TraitBB for Docs2 {
fn test_4(&self) {}
}
impl TraitCC for Docs2 {
fn test_5(&self) {}
}
fn test_fn<T: TraitA + TraitB, U: TraitAA + TraitBB + TraitCC>(x: T, y: Vec<Box<U>>) {
x.test_1();
x.test_2();
for item in y {
item.test_3();
item.test_4();
item.test_5();
}
}
Call as follows,yy parameter error: mismatched type expected Docs1, found Docs2, but my Docs1 and Docs2 both implement the same trait, why do I report this error
let xx = Book;
let yy = vec![Box::new(Docs1), Box::new(Docs2)];
test_fn(xx, yy);
How do you solve this?