Skip to main content

any

Macro any 

Source
macro_rules! any {
    ($(,)?) => { ... };
    ($matcher:expr $(,)?) => { ... };
    ($head:expr, $head2:expr $(,)?) => { ... };
    ($head:expr, $head2:expr, $($tail:expr),+ $(,)?) => { ... };
}
Expand description

Matches a value which at least one of the given matchers match.

Each argument is a Matcher which matches against the actual value.

For example:

verify_that!("A string", any!(starts_with("A"), ends_with("string")))?; // Passes
verify_that!("A string", any!(starts_with("A"), starts_with("string")))?; // Passes
verify_that!("A string", any!(ends_with("A"), ends_with("string")))?; // Passes
verify_that!("A string", any!(starts_with("An"), ends_with("not a string")))?; // Fails

Using this macro is equivalent to using the or method:

verify_that!(10, gt(9).or(lt(8)))?; // Also passes

Assertion failure messages are not guaranteed to be identical, however.

If an inner matcher is eq(...), it can be omitted:


verify_that!(123, any![lt(1), 123, gt(1000)])