macro_rules! requirements {
([$($requirement:ident),* $(,)?] $(,)?) => { ... };
($error:ty, [$($requirement:ident),* $(,)?] $(,)?) => { ... };
}
Available on crate feature
require
only.Expand description
Check multiple requirement!
s
§Example
use swift_check::{
require::{Requirement, check},
requirement, requirements,
eq
};
requirement!(pub space => eq(b' ') =>! "There needs to be a space!");
requirement!(pub seven => eq(b'7') =>! "There needs to be a seven!");
let (valid, res) = check(
b"example input 7",
requirements!([space, seven])
).results();
// The first element of result denotes if all bytes met at least one of the conditions, in this
// case this is false.
assert!(!valid);
// the res is an iterator over each requirement! result. You also can use `result` instead of
// `results` if you only need to know all requirements were met and care less about granular
// error reporting.
§Error Handling
The individual requirements do not need to share the same error type, but they do all need to
implement either From
or Into
the requirements!
error type.
§Syntax
Error Type, [Requirements, ...]
or for when you’re feeling lazy, the default error is ErrMsg
, the above example uses this.
[Requirements, ...]