Skip to content

Commit 12c3e29

Browse files
igor-petrukqwandor
andauthored
Update match-guards.md (#233)
* Update match-guards.md Adding more information how match guards are different from simply using "if" inside of the match case, after the case has matched. * Be consistent about naming of match arms. Co-authored-by: Andrew Walbran <qwandor@google.com>
1 parent 9148728 commit 12c3e29

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/pattern-matching/match-guards.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,14 @@ expression which will be executed if the pattern matches:
66
```rust,editable
77
{{#include ../../third_party/rust-by-example/match-guards.rs}}
88
```
9+
10+
<details>
11+
12+
Match guards as a separate syntax feature are important and necessary. They are not
13+
the same as separate `if` expression inside of the match arm.
14+
15+
An `if` expression inside of the branch block (after `=>`) happens after the match arm
16+
is selected. Failing the `if` condition inside of that block won't result in other arms
17+
of the original `match` expression being considered.
18+
19+
</details>

0 commit comments

Comments
 (0)