Add `matches!` Individual examples.

对读者首次接触**matches!宏**的例子进一步说明,因为**匹配守卫**在**2.6.4. 全模式列表**章节才有介绍。
pull/473/head
Rustln 3 years ago committed by GitHub
parent fdaedf9c0f
commit 5124a9efce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -299,6 +299,8 @@ let bar = Some(4);
assert!(matches!(bar, Some(x) if x > 2)); assert!(matches!(bar, Some(x) if x > 2));
``` ```
表达式 `Some(x) if x > 2``if` 能为分支模式提供更进一步的匹配条件,在模式匹配中简称**匹配守卫**match guard
## 变量覆盖 ## 变量覆盖
无论是是 `match` 还是 `if let`,他们都可以在模式匹配时覆盖掉老的值,绑定新的值: 无论是是 `match` 还是 `if let`,他们都可以在模式匹配时覆盖掉老的值,绑定新的值:
```rust ```rust

Loading…
Cancel
Save