Macro swift_check::one_of

source ·
macro_rules! one_of {
    ($left:expr $(,)?) => { ... };
    ($left:expr, $right:expr $(,)?) => { ... };
    ($first:expr, $second:expr, $third:expr $(,)?) => { ... };
    ($first:expr, $second:expr, $third:expr, $fourth:expr $(,)?) => { ... };
}
Expand description

Ensure only one of the conditions are true

§Arguments

  • condition, … - The conditions to check, only allowing one to hold (up to 4)

§Example

use swift_check::{one_of, for_all_ensure, eq, range};

let input = b"123456789";
let char_or_num = for_all_ensure(
    input, one_of!(range!(b'0'..=b'9'), range!(b'a'..=b'z'), range!(b'A'..=b'Z'))
);
assert!(char_or_num);

let should_fail = for_all_ensure(
    input,
    one_of!(range!(b'0'..=b'9'), range!(b'0'..=b'9'), range!(b'0'..=b'9'))
);
assert!(!should_fail)