if let
Expressions
The
if let
expression
lets you execute different code depending on whether a value matches a pattern:
Speaker Notes
- Unlike
match
,if let
does not have to cover all branches. This can make it more concise thanmatch
. - A common usage is handling
Some
values when working withOption
. - Unlike
match
,if let
does not support guard clauses for pattern matching. - With an
else
clause, this can be used as an expression.