1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-01-23 22:13:02 +02:00

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>
This commit is contained in:
Igor Petruk 2023-01-23 13:09:32 +00:00 committed by GitHub
parent 91487289d2
commit 12c3e2989d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,3 +6,14 @@ expression which will be executed if the pattern matches:
```rust,editable
{{#include ../../third_party/rust-by-example/match-guards.rs}}
```
<details>
Match guards as a separate syntax feature are important and necessary. They are not
the same as separate `if` expression inside of the match arm.
An `if` expression inside of the branch block (after `=>`) happens after the match arm
is selected. Failing the `if` condition inside of that block won't result in other arms
of the original `match` expression being considered.
</details>