File: lib.rs

package info (click to toggle)
rust-is-match 0.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, sid, trixie
  • size: 100 kB
  • sloc: makefile: 2
file content (23 lines) | stat: -rw-r--r-- 530 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#[macro_export]
macro_rules! is_match {
    ($expression: expr, $($pattern:tt)+) => {
        is_match! {tt
            match $expression {
                $($pattern)+ => true,
                _            => false
            }
        }
    };
    (tt $value:expr) => ($value);
}

#[test]
fn test_matching() {
    let foo = Some("-12");
    assert!(is_match!(foo, Some(bar) if
        is_match!(bar.as_bytes()[0], b'+' | b'-') &&
        is_match!(bar.as_bytes()[1], b'0'...b'9')
    ));
    assert!(!is_match!(foo, None));
}