Artificial intelligent assistant

Rust: Vec にトレイトを実装したオブジェクトを格納したい "Trait " Rust `Vec` Trait `Vec` () trait Trait<T>{} struct Struct<T> { a: Vec<Trait<T>> } fn main() {} error[E0277]: the trait bound `Trait<B> + 'static: std::marker::Sized` is not satisfied. = note: `Trait<B> + 'static` does not have a constant size known at compile-time = note: required by `std::vec::Vec`

2

#

`Struct``Trait`Rust`PhantomData`unused type parameter


use std::marker::PhantomData;

trait Trait {}

struct Struct
where Impl: Trait
{
a: Vec,
phantom: PhantomData,
}

fn main() {}


#

1`Box`


trait Trait {}

struct Struct {
a: Vec>>,
}

fn main() {}


`&``&mut``Rc`

#


vtable




trait Trait {}

struct Struct {
a: Vec>>,
}

impl Trait for () {}
impl Trait for bool {}


fn main() {
let mut s: Struct<()> = Struct { a: vec![] };
s.a.push(Box::new(()));
s.a.push(Box::new(true));
}


xcX3v84RxoQ-4GxG32940ukFUIEgYdPy cf0a64253cdb4fee4624ec19776a9180