Structs

We can match on specific arguments inside a struct while ignoring the rest by using ...

struct Point {
    x: u64,
    y: u64
}

fn struct_matching() {
    let point = Point {
        x: 1u64,
        y: 2u64,
    };

    let result = match point {
        Point { x: 5, y } => y + 1,
        Point { x, .. } => x,
        Point { y, .. } => y,
        _ => 42,
    };
}

If the struct is imported from another module and has private fields, the private fields must always be ignored by using ...