4 ms·
Match has the syntax of: match value { pattern(variable-binding) [if guard-condition] => matched result ... } In this case, the first
by ww520 12y ago
Match has the syntax of:
match value {
pattern(variable-binding) [if guard-condition] => matched result
...
}
In this case, the first 'even' is variable declaration binding it to val. The next 'if even % 2 == 0' is the guard expression, qualifying the range of values of the 'even' variable. The 'if' is a keyword, indicating a guard expression. The next '=> Some(even)' returns an Option type wrapping the matching 'even' values.
The wildcard _ matches whatever left, which is the non-even values of val.