Skip to main content

MatcherExt

Trait MatcherExt 

Source
pub trait MatcherExt: Sized {
    // Provided methods
    fn and<Right>(self, right: Right) -> ConjunctionMatcher<Self, Right> { ... }
    fn or<Right>(self, right: Right) -> DisjunctionMatcher<Self, Right> { ... }
}
Expand description

Extension methods for composing matchers.

This trait is implemented for all Sized types, but the resulting combinators are only useful when the underlying types implement Matcher.

Provided Methods§

Source

fn and<Right>(self, right: Right) -> ConjunctionMatcher<Self, Right>

Constructs a matcher that matches both self and right.

verify_that!("A string", starts_with("A").and(ends_with("string")))?; // Passes
verify_that!("A string", starts_with("Another").and(ends_with("string")))?; // Fails
verify_that!("A string", starts_with("A").and(ends_with("non-string")))?; // Fails
Source

fn or<Right>(self, right: Right) -> DisjunctionMatcher<Self, Right>

Constructs a matcher that matches when at least one of self or right matches the input.

verify_that!(10, eq(2).or(ge(5)))?;  // Passes
verify_that!(10, eq(2).or(eq(5)).or(ge(9)))?;  // Passes
verify_that!(10, eq(2).or(ge(15)))?; // Fails

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<M: Sized> MatcherExt for M