









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"); } }
该文展示了Rust编程中使用i8类型变量、Option枚举以及match和iflet语句进行条件判断和值匹配的示例代码,重点在于变量赋值及条件分支的优化写法。
1732

被折叠的 条评论
为什么被折叠?



