你如何访问枚举中的结构?

时间:2018-03-27 19:22:46

标签: struct enums rust

Rust书有examples of assigning them but not a single one showing how to access them

pub enum Animal {
    Ant(Ant),
    Bear,
}

pub struct Ant {
    pub species: usize,
}

fn test(a: Ant) {
    println!("{:?}", a.species);
}

fn main() {
    let a: Animal = Animal::Ant(Ant { species: 1 });
    let b: Animal = Animal::Bear;

    test(a);
}

如何将Ant a结构转换为test函数?

0 个答案:

没有答案