How to destructure a struct

Destructure a Rust struct by matching its fields with curly braces in a pattern to extract values into variables.

You destructure a struct by using curly braces with field names in a pattern, such as inside a match arm or an if let statement.

struct Point { x: i32, y: i32 }

let p = Point { x: 10, y: 20 };

match p {
    Point { x, y } => println!("x: {x}, y: {y}"),
}

This creates variables x and y bound to the struct's field values.