Function xpct::any

source ·
pub fn any<'a, T>(
    block: impl Fn(&mut CombinatorContext<T>) + 'a
) -> Matcher<'a, T, T>where
    T: 'a,
Expand description

Succeeds when any of the passed matchers succeed.

This is a matcher than can be used to compose other matchers. This matcher doesn’t short-circuit; it tests all the matchers that are passed to it.

This matcher doesn’t chain the output of each matcher into the next. Instead, it owns its value and passes it to each matcher, either by reference, or by value if the value is Clone or Copy. The closure you pass to this matcher accepts a CombinatorContext, which has methods like borrow, cloned and copied to determine how the value is passed to matchers. From there, you can call to and to_not to use matchers.

Examples

Passing the value to matchers by reference:

use xpct::{any, expect, have_prefix};

expect!("https://example.com").to(any(|ctx| {
    ctx.borrow::<str>()
        .to(have_prefix("http://"))
        .to(have_prefix("https://"));
}));

Passing the value to matchers by value via Copy:

use xpct::{expect, any, be_gt, be_lt};

expect!(60).to(any(|ctx| {
    ctx.copied()
        .to(be_lt(41))
        .to(be_gt(57));
}));