We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c21f73e commit 0dad9dcCopy full SHA for 0dad9dc
src/doc/book/patterns.md
@@ -23,6 +23,33 @@ match x {
23
24
This prints `one`.
25
26
+It's possible to create a binding for the value in the any case:
27
+
28
+```rust
29
+let x = 1;
30
31
+match x {
32
+ y => println!("x: {} y: {}", x, y),
33
+}
34
+```
35
36
+This prints:
37
38
+```text
39
+x: 1 y: 1
40
41
42
+Note it is an error to have both a catch-all `_` and a catch-all binding in the same match block:
43
44
45
46
47
48
49
+ _ => println!("anything"), // this causes an error as it is unreachable
50
51
52
53
There’s one pitfall with patterns: like anything that introduces a new binding,
54
they introduce shadowing. For example:
55
0 commit comments