Crate swift_check

source ·
Expand description
use swift_check::{search, range, one_of, any, all, eq, not};

let input = b"
    swift-check is a high performance library for searching or validating data based on \
    expressive conditions
";

let cond = all!(
    all!(any!(range!(b'a'..=b'z'), range!(b'A'..=b'Z'), eq(b' ')), not(range!(b'0'..=b'9'))),
    one_of!(eq(b' '), range!(b'a'..=b'z'), range!(b'a'..=b'z'))
);

let Some(first_space) = search(input, cond) else {
    unreachable!("There's a space!")
};

assert_eq!(input[first_space], b' ');

// or, more simply

let Some(first_space2) = search(input, eq(b' ')) else {
    unreachable!("There's a space!")
};

assert_eq!(input[first_space2], b' ');
assert_eq!(first_space2, first_space);

Modules§

Macros§

  • Check that all the conditions hold
  • Check that any of the conditions hold
  • Check that the condition holds for all bytes
  • Ensure only one of the conditions are true
  • Check that the value is within the specified range

Functions§

  • Combine two conditions
  • Check if the bytes are equal to expected
  • Find the first circumstance of the condition being met
  • For all the bytes, ensure that the condition holds
  • For all the bytes, ensure that the condition holds
  • Negate a condition
  • Check that either condition is met
  • Find the first byte that meets the cond
  • Check that only one of the conditions are met