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§

arch
requirerequire
Ensure each requirement was met

Macros§

all
Check that all the conditions hold
any
Check that any of the conditions hold
one_of
Ensure only one of the conditions are true
range
Check that the value is within the specified range
requirementrequire
Define a Requirement
requirementsrequire
Check multiple requirement!s

Functions§

and
Combine two conditions
ensure
Check that the condition holds for all bytes
eq
Check if the bytes are equal to expected
find
Find the first circumstance of the condition being met
for_all_ensure
For all the bytes, ensure that the condition holds
for_all_ensure_ct
For all the bytes, ensure that the condition holds
not
Negate a condition
or
Check that either condition is met
search
Find the first byte that meets the cond
xor
Check that only one of the conditions are met