#[derive(Default)]
struct Bar;
#[derive(Default)]
struct Baz;
fn main() {
let mut vec = Vec::<Box<dyn Default>>::new();
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::default::Default` cannot be made into an object
vec.push(Box::new(Bar));
vec.push(Box::new(Baz));
}
Default is a sized Trait, which means you cannot convert it to a trait object.
For the example above, is there a workaround so I can store sized traits in a Vec
(or any other collection)?