Why can't I write the following code?
trait MyTrait {
fn my_fun(&self);
}
struct MyStruct<T:MyTrait> {
a: Rc<T>
}
fn main() {
let x: MyStruct<dyn MyTrait> = (...);
}
It seems to me that, at least conceptually, it should be correct.
Why can't I write the following code?
trait MyTrait {
fn my_fun(&self);
}
struct MyStruct<T:MyTrait> {
a: Rc<T>
}
fn main() {
let x: MyStruct<dyn MyTrait> = (...);
}
It seems to me that, at least conceptually, it should be correct.
Because, as the compiler error tells, T: MyTrait
implicitly means T: MyTrait + Sized
, and dyn MyTrait
is not Sized
.
Thanks.
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.