fn inc(x: Option) -> Option { match x { Some(v) => Some(v + 1), // 一般这里应该是None None => None, } } fn main() { let s = Some(5); println!("{:?}", s); // 自动推断 let op: Option<_> = Some(2); println!("{:?}", op); match op { Some(x) => println!("{}", x), None => println!("none"), } // Some(3) // None println!("{:?}", inc(op)); println!("{:?}", inc(None)); if let Some(v) = inc(op) { println!("v:{}", v); } else { println!("none"); } if let Some(v) = inc(None) { println!("v:{}", v); } else { println!("none"); } }