#[derive(Debug)] enum Shape { Circle { r: f64 }, Rect { w: f64, h: f64 }, Dot } fn main() { let shapes=[Shape::Circle {r:1.0},Shape::Rect {w:2.0,h:3.0},Shape::Dot]; fn area(s: &Shape) -> f64 { match s { Shape::Circle { r } => 3.14159 * r * r, Shape::Rect { w, h } => w * h, Shape::Dot => 0.0, } } for s in &shapes { let description = match s { Shape::Circle { r } => format!("Shape.Circle {{ {r} }}"), Shape::Rect { w, h } => format!("Shape.Rect {{ {w}, {h} }}"), Shape::Dot => "Shape.Dot".to_owned(), }; println!("{description} area {}", area(s)); } assert_eq!(area(&Shape::Rect {w:2.0,h:3.0}),6.0); }