trait KKK {
fn hi();
}
struct Test<A>
where A : KKK {
var : A,
}
impl<A> Test<A>
where A : KKK {
fn haha(&mut self) {self.var = Test2{};}
}
struct Test2 {}
impl KKK for Test2 {
fn hi() {}
}
fn main() {
let ins2 = Test{var : Test2{}};
ins2.haha();
}
I have this error:
error[E0308]: mismatched types
--> trait.rs:12:36
|
12 | fn haha(&mut self) {self.var = Test2{};}
| ^^^^^^^ expected type parameter, found struct `Test2`
|
= note: expected type `A`
found type `Test2`
error: aborting due to previous error
I can assign a Test2 instance to ins2's var in main, but I cant assign to var inside haha?
How do I modify haha to allow me assign any struct that implements KKK to var?
Because A can be type other than Test2 which also impls KKK. Assuming there's Test3 which also impls KKK, it's obvious that we can't call .haha() on Test<Test3>, as it's var is not a Test2.