Common Data Structures
Enumeration

Structure

Last updated


Last updated
enum Direction {
Up,
Down,
Left,
Right,
}
fn which_way(go: Direction) -> &'static str {
match go {
Direction::Up => "up",
Direction::Down => "down",
Direction::Left => "left",
Direction::Right => "right",
}
}struct ShippingBox {
depth: i32,
width: i32,
height: i32,
}
fn main() {
let my_box = ShippingBox {
depth: 3,
width: 2,
height: 5,
};
let tall = my_box.height;
println!("the box is {:?} units tall", tall);
}