📜  泛型类型的 rust vec - 无论代码示例

📅  最后修改于: 2022-03-11 14:57:16.447000             🧑  作者: Mango

代码示例1
trait Foo { }

pub struct A {}
pub struct B {}

impl Foo for A {}
impl Foo for B {}

type FooT = Box;

fn test() -> Vec {
    let mut generic_vec: Vec = Vec::new();
    generic_vec.push(Box::new(A {}));
    generic_vec.push(Box::new(B {}));
    return generic_vec;
}