嵌套解构
2021-10-31

嵌套结构


rust 支持嵌套解构

pub enum Inner {
    A(i32),
    B(u32)
}

pub enum Outer {
    Span,
    P(Inner)
}

fn main() {
    let x = Outer::P(Inner::A(12));
    if let Outer::P(Inner::A(i)) = x {
        println!("{}", i);
    }
}