rust
Rust Programming seahorse 3 years ago 100%

How to retrieve value of EnumItemStruct property?

I'm playing with the following code and can't seem to find an example where I can get the values of one of the coordinates.

enum Coordinates {
    Point1 { x: i32, y: i32 },
    Point2 { x: i32, y: i32 },
}
fn main() {
    let p1 = Coordinates::Point1{ x: 0, y: 45};
    let x = p1.x; //Doesn't work
}

How can I get the value of x or y?

3
3
Comments 3