What is exhaustive matching

Exhaustive matching is a Rust compiler rule requiring all enum variants to be handled in a match expression to prevent unhandled cases.

Exhaustive matching requires a match expression to handle every possible variant of an enum or pattern, ensuring no cases are left unhandled at compile time.

enum IpAddrKind {
    V4,
    V6,
}

fn route(ip_kind: IpAddrKind) {
    match ip_kind {
        IpAddrKind::V4 => println!("V4"),
        IpAddrKind::V6 => println!("V6"),
    }
}

If you omit a variant, the compiler will refuse to compile the code until all possibilities are covered.