1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#[macro_export]
macro_rules! matches {
($expr:expr, $($pat:tt)+) => {
_tt_as_expr_hack! {
match $expr {
$($pat)+ => true,
_ => false
}
}
}
}
#[doc(hidden)]
#[macro_export]
macro_rules! _tt_as_expr_hack {
($value:expr) => ($value)
}
#[test]
fn test_matches() {
let foo = Some("-12");
assert!(matches!(foo, Some(bar) if
matches!(bar.as_bytes()[0], b'+' | b'-') &&
matches!(bar.as_bytes()[1], b'0'... b'9')
));
}