diff --git a/src/control-flow/if-let-expressions.md b/src/control-flow/if-let-expressions.md index 9c9a9c6d..a593fdf6 100644 --- a/src/control-flow/if-let-expressions.md +++ b/src/control-flow/if-let-expressions.md @@ -19,8 +19,21 @@ Rust.
* `if let` can be more concise than `match`, e.g., when only one case is interesting. In contrast, `match` requires all branches to be covered. - * For the similar use case consider demonstrating a newly stabilized [`let else`](https://github.com/rust-lang/rust/pull/93628) feature. * A common usage is handling `Some` values when working with `Option`. * Unlike `match`, `if let` does not support guard clauses for pattern matching. +* Since 1.65, a similar [let-else](https://doc.rust-lang.org/rust-by-example/flow_control/let_else.html) construct allows to do a destructuring assignment, or if it fails, have a non-returning block branch (panic/return/break/continue): + + ```rust,editable + fn main() { + println!("{:?}", second_word_to_upper("foo bar")); + } + + fn second_word_to_upper(s: &str) -> Option { + let mut it = s.split(' '); + let (Some(_), Some(item)) = (it.next(), it.next()) else { + return None; + }; + Some(item.to_uppercase()) + }