How to Use if let with Enums in Rust

Use `if let` to concisely match a single enum variant and execute code only when that specific case occurs.

Use if let to match a single enum variant and execute code only when that variant is present, avoiding the verbosity of a full match statement.

enum Message {
    Quit { x: i32, y: i32 },
    Move { x: i32, y: i32 },
    Write(String),
    ChangeColor(u8, u8, u8),
}

fn main() {
    let msg = Message::Quit { x: 0, y: 0 };

    if let Message::Quit { x, y } = msg {
        println!("Shutting down at ({}, {})", x, y);
    }
}