parent
48ca6d1840
commit
72beb1f885
1 changed files with 16 additions and 0 deletions
|
@ -3991,6 +3991,22 @@ match origin {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
You can do this kind of match on any member, not just the first:
|
||||||
|
|
||||||
|
```{rust}
|
||||||
|
# #![allow(non_shorthand_field_patterns)]
|
||||||
|
struct Point {
|
||||||
|
x: int,
|
||||||
|
y: int,
|
||||||
|
}
|
||||||
|
|
||||||
|
let origin = Point { x: 0i, y: 0i };
|
||||||
|
|
||||||
|
match origin {
|
||||||
|
Point { y: y, .. } => println!("y is {}", y),
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
Whew! That's a lot of different ways to match things, and they can all be
|
Whew! That's a lot of different ways to match things, and they can all be
|
||||||
mixed and matched, depending on what you're doing:
|
mixed and matched, depending on what you're doing:
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue