You need to figure out the variant before you can access any fields.
let x = match p1 {
Coordinates::Point1 { x, .. } => x, // .. means "I don't care about the other fields"
Coordinates::Point2 { x, .. } => x,
};
or if you only need to do stuff on one type of point
if let Coordinates::Point1 { x, _y } = p1 {
// Do stuff with x or y here
// _y (prefixed / replaced with _) means "I won't use that variable"
}
However it looks like what you want is a struct that contains an enum and the coordinates.
enum CoordinateKind {
Point1,
Point2,
}
struct Point {
kind: CoordinateKind,
x: i32,
y: i32,
}
fn main() {
let p = Point {
kind: CoordinateKind::Point1,
x: 0,
y: 45,
};
let x = p.x;
}