<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # if let > [if-let.md](https://github.com/rust-lang/rust/blob/master/src/doc/book/if-let.md) commit 797a0bd1c13175398aa0e2e45f6dbb61bcb8c329 `if let`允許你合并`if`和`let`來減少特定類型模式匹配的開銷。 例如,讓我們假設我們有一些`Option<T>`。我們想讓它是`Some<T>`時在其上調用一個函數,而它是`None`時什么也不做。這看起來像: ~~~ # let option = Some(5); # fn foo(x: i32) { } match option { Some(x) => { foo(x) }, None => {}, } ~~~ 我們并不一定要在這使用`match`,例如,我們可以使用`if`: ~~~ # let option = Some(5); # fn foo(x: i32) { } if option.is_some() { let x = option.unwrap(); foo(x); } ~~~ 這兩種選項都不是特別吸引人。我們可以使用`if let`來優雅地完成相同的功能: ~~~ # let option = Some(5); # fn foo(x: i32) { } if let Some(x) = option { foo(x); } ~~~ 如果一個[模式](#)匹配成功,它綁定任何值的合適的部分到模式的標識符中,并計算這個表達式。如果模式不匹配,啥也不會發生。 如果你想在模式不匹配時做點其他的,你可以使用`else`: ~~~ # let option = Some(5); # fn foo(x: i32) { } # fn bar() { } if let Some(x) = option { foo(x); } else { bar(); } ~~~ ### `while let` 類似的,當你想一直循環,直到一個值匹配到特定的模式的時候,你可以選擇使用`while let`。使用`while let`可以把類似這樣的代碼: ~~~ let mut v = vec![1, 3, 5, 7, 11]; loop { match v.pop() { Some(x) => println!("{}", x), None => break, } } ~~~ 變成這樣的代碼: ~~~ let mut v = vec![1, 3, 5, 7, 11]; while let Some(x) = v.pop() { println!("{}", x); } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看