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
函数?