美文网首页
rust--如何获取再Some里面的值?

rust--如何获取再Some里面的值?

作者: 极光火狐狸 | 来源:发表于2018-08-29 10:44 被阅读9次
fn example1() {
    let a = Some("hello");
    match a {
        Some(b) => println!("show variable a: {}", b),
        _ => println!("nothing")
    }
}


fn example2() {
    let a = Some("hello");
    println!("show variable a: {}", a.unwrap())
}


fn main() {
    example1();
    example2();
}

相关文章

网友评论

      本文标题:rust--如何获取再Some里面的值?

      本文链接:https://www.haomeiwen.com/subject/mzdhwftx.html