How to Use the match Expression with Enums

Use the `match` keyword to handle every variant of an enum explicitly, ensuring exhaustive and safe control flow.

Use the match keyword to destructure an enum value by listing every variant in separate arms. This ensures exhaustive handling of all possible states defined in your enum.

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

fn main() {
    let msg = Message::Quit;

    match msg {
        Message::Quit => println!("Quit"),
        Message::Move { x, y } => println!("Move to {}, {}", x, y),
        Message::Write(text) => println!("Text message: {}", text),
        Message::ChangeColor(r, g, b) => println!("Change color to {}, {}, {}", r, g, b),
    }
}