相关疑难解决方法(0)

如何在Rust中访问枚举值?

struct Point {
    x: f64,
    y: f64,
}

enum Shape {
    Circle(Point, f64),
    Rectangle(Point, Point),
}

let my_shape = Shape::Circle(Point { x: 0.0, y: 0.0 }, 10.0);
Run Code Online (Sandbox Code Playgroud)

我想打印出circle第二个属性,这里是10.0.我试过my_shape.lastmy_shape.second,但既不工作.

在这种情况下,我该怎么办才能打印10.0?

rust

25
推荐指数
7
解决办法
1万
查看次数

标签 统计

rust ×1