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.
2 parents 5c1619c + 491e0af commit c1ccd64Copy full SHA for c1ccd64
text/2005-match-ergonomics.md
@@ -8,21 +8,33 @@
8
9
Better ergonomics for pattern-matching on references.
10
11
-Currently:
+Currently, matching on references requires a bit of a dance using
12
+`ref` and `&` patterns:
13
14
```
15
+let x: &Option<_> = &Some(0);
16
+
17
+match x {
18
+ &Some(ref y) => { ... },
19
+ &None => { ... },
20
+}
21
22
+// or using `*`:
23
24
match *x {
- Foo(ref x) => { ... }
- Bar(ref mut y, z) => { ... }
25
+ Some(ref x) => { ... },
26
+ None => { ... },
27
}
28
29
-Proposed:
30
+After this RFC, the above form still works, but now we also allow a simpler form:
31
32
33
34
35
match x {
- Foo(x) => { ... }
- Bar(y, z) => { ... }
36
+ Some(y) => { ... }, // `y` is a reference to `0`
37
38
39
40
0 commit comments