fn main() { let x: i8 = 5; let y:i8 = Some(5).expect("Invalid number"); let sum = x + y; println!("{}", sum); }
fn main() { let v = Some(0u8); match v { Some(3) => println!("three"), _ => (), } //优化上面写法 if let Some(3) = v { println!("three"); } }
fn main() { let v = Some(0u8); match v { Some(3) => println!("three"), _ => println!("others"), } //优化上面写法 if let Some(3) = v { println!("three"); } else { println!("others"); } }