is_match/
lib.rs

1#[macro_export]
2macro_rules! is_match {
3    ($expression: expr, $($pattern:tt)+) => {
4        is_match! {tt
5            match $expression {
6                $($pattern)+ => true,
7                _            => false
8            }
9        }
10    };
11    (tt $value:expr) => ($value);
12}
13
14#[test]
15fn test_matching() {
16    let foo = Some("-12");
17    assert!(is_match!(foo, Some(bar) if
18        is_match!(bar.as_bytes()[0], b'+' | b'-') &&
19        is_match!(bar.as_bytes()[1], b'0'...b'9')
20    ));
21    assert!(!is_match!(foo, None));
22}
23