I want the enum to act like a variant with the struct I previously defined:
pub struct Element {
symbol: String,
atomic_number: u8,
atomic_mass: f32,
}
pub struct Hydrogen {
element: Element,
}
pub struct Helium {
element: Element,
}
pub struct Lithium {
element: Element,
}
pub enum ElementKind {
HYDROGEN(Hydrogen),
HELIUM(Helium),
LITHIUM(Lithium,
}
impl Default for Hydrogen {
fn default() -> Self {
Hydrogen {
element: Element {
symbol: "H".to_string(),
atomic_number: 1,
atomic_mass: 1.008,
},
}
}
}
impl Default for Helium {
fn default() -> Self {
Helium {
element: Element {
symbol: "He".to_string(),
atomic_number: 2,
atomic_mass: 4.003,
},
}
}
}
impl Default for Lithium {
fn default() -> Self {
Lithium {
element: Element {
symbol: "Li".to_string(),
atomic_number: 3,
atomic_mass: 6.491,
},
}
}
}
fn main() {
let e = ElementKind::HYDROGEN;
match e {
// TODO
}
}
What is the correct way to write the match
statement in order to, for example, always print out the symbol
of the element?