Skip to content

Commit 72beb1f

Browse files
committed
Extra note about struct matching order
Fixes #19178
1 parent 48ca6d1 commit 72beb1f

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/doc/guide.md

+16
Original file line numberDiff line numberDiff line change
@@ -3991,6 +3991,22 @@ match origin {
39913991
}
39923992
```
39933993

3994+
You can do this kind of match on any member, not just the first:
3995+
3996+
```{rust}
3997+
# #![allow(non_shorthand_field_patterns)]
3998+
struct Point {
3999+
x: int,
4000+
y: int,
4001+
}
4002+
4003+
let origin = Point { x: 0i, y: 0i };
4004+
4005+
match origin {
4006+
Point { y: y, .. } => println!("y is {}", y),
4007+
}
4008+
```
4009+
39944010
Whew! That's a lot of different ways to match things, and they can all be
39954011
mixed and matched, depending on what you're doing:
39964012

0 commit comments

Comments
 (0)