How can I pattern match against an Option?

后端 未结 4 1007
臣服心动
臣服心动 2021-01-01 10:13

I can straight-forwardly match a String in Rust:

let a = \"hello\".to_string();

match &a[..] {
    \"hello\" => {
        println!(\"Mat         


        
4条回答
  •  隐瞒了意图╮
    2021-01-01 10:57

    As of Rust 1.40, you can now use as_deref instead of the top answers:

    match args.nth(1).as_deref() {
        Some("help") => {}
        Some(s) => {}
        None => {}
    }
    

    I found this because it is one of the clippy lints.

提交回复
热议问题