How to use nested pattern matching

Use nested patterns in a match expression to destructure enum variants and tuples simultaneously.

Use nested patterns inside a match expression to destructure data within enum variants or tuples in a single step. This allows you to match on the outer type and immediately bind or check the inner values without multiple nested match statements.

enum IpAddr {
    V4(u8, u8, u8, u8),
    V6(String),
}

fn route(ip: IpAddr) {
    match ip {
        IpAddr::V4(a, b, c, d) => println!("V4: {}.{}.{}.{}", a, b, c, d),
        IpAddr::V6(s) => println!("V6: {}", s),
    }
}