面试题答案
一键面试// 定义表示几何形状的枚举
enum Shape {
Circle(f64),
Rectangle(f64, f64),
}
// 计算不同形状面积的函数
fn area(shape: &Shape) -> f64 {
match shape {
Shape::Circle(radius) => std::f64::consts::PI * radius * radius,
Shape::Rectangle(length, width) => length * width,
}
}