Use @ to bind a pattern to a name.
1
2
3
4
5
6
| let foo = 4;
match foo {
x @ 0..=5 => assert_eq!(x,4),
y @ _ => panic!("{}-too many!", y)
}
|
1
2
3
4
5
6
| let point: (u32,u32) = (1, 2);
match point {
(1, y @ _) => assert_eq!(y,2),
_ => {}
}
|
1
2
3
4
5
| let point: (u32,u32) = (1, 2);
let mypoint @ (x, _) = point;
assert_eq!(x,1);
assert_eq(mypoint,point);
|