pub trait Matcher<T: Debug + ?Sized> {
    fn matches(&self, actual: &T) -> MatcherResult;
    fn describe(&self, matcher_result: MatcherResult) -> String;

    fn explain_match(&self, actual: &T) -> MatchExplanation { ... }
}
Expand description

An interface for checking an arbitrary condition on a datum.

Required Methods§

source

fn matches(&self, actual: &T) -> MatcherResult

Returns whether the condition matches the datum actual.

The trait implementation defines what it means to “match”. Often the matching condition is based on data stored in the matcher. For example, eq matches when its stored expected value is equal (in the sense of the == operator) to the value actual.

source

fn describe(&self, matcher_result: MatcherResult) -> String

Returns a description of self or a negative description if matcher_result is DoesNotMatch.

The function should print a verb phrase that describes the property a value matching, respectively not matching, this matcher should have. The subject of the verb phrase is the value being matched.

For example, eq(7).describe(MatcherResult::Matches) prints “is equal to 7”.

Provided Methods§

source

fn explain_match(&self, actual: &T) -> MatchExplanation

Prepares a MatchExplanation describing how the expected value encoded in this instance matches or does not match the given value actual.

The default implementation relies on [Describe::describe].

Implementors§

source§

impl<ActualT: AsRef<str> + Debug + ?Sized> Matcher<ActualT> for ContainsRegexMatcher

source§

impl<ActualT: Debug + PartialOrd<ExpectedT>, ExpectedT: Debug> Matcher<ActualT> for GeMatcher<ExpectedT>

source§

impl<ActualT: Debug + PartialOrd<ExpectedT>, ExpectedT: Debug> Matcher<ActualT> for LeMatcher<ExpectedT>

source§

impl<ActualT: Debug + PartialOrd<ExpectedT>, ExpectedT: Debug> Matcher<ActualT> for LtMatcher<ExpectedT>

source§

impl<ExpectedT, ActualT> Matcher<ActualT> for EqIgnoringCaseMatcher<ExpectedT>where
    ExpectedT: Deref<Target = str>,
    ActualT: AsRef<str> + Debug + ?Sized,

source§

impl<PatternT, ActualT> Matcher<ActualT> for MatchesRegexMatcher<PatternT>where
    PatternT: Deref<Target = str>,
    ActualT: AsRef<str> + Debug + ?Sized,

source§

impl<PrefixT, ActualT> Matcher<ActualT> for StartsWithMatcher<PrefixT>where
    PrefixT: Deref<Target = str>,
    ActualT: AsRef<str> + Debug + ?Sized,

source§

impl<SubstringT, ActualT> Matcher<ActualT> for ContainsSubstringMatcher<SubstringT>where
    SubstringT: Deref<Target = str>,
    ActualT: AsRef<str> + Debug + ?Sized,

source§

impl<SuffixT, ActualT> Matcher<ActualT> for EndsWithMatcher<SuffixT>where
    SuffixT: Deref<Target = str>,
    ActualT: AsRef<str> + Debug + ?Sized,

source§

impl<T: PartialEq + Debug, ContainerT: PartialEq + Debug> Matcher<ContainerT> for ContainerEqMatcher<ContainerT>where
    for<'a> &'a ContainerT: IntoIterator<Item = &'a T>,

source§

impl<T: PartialEq + Debug, const N: usize> Matcher<[T]> for ContainerEqMatcher<[T; N]>

source§

impl<T: PartialEq + Debug, const N: usize> Matcher<Vec<T, Global>> for ContainerEqMatcher<[T; N]>

source§

impl<T: Debug + Float> Matcher<T> for NearMatcher<T>

source§

impl<T: Debug, InnerMatcherT: Matcher<T>, ContainerT: Debug> Matcher<ContainerT> for ContainsMatcher<InnerMatcherT>where
    for<'a> &'a ContainerT: IntoIterator<Item = &'a T>,

source§

impl<const N: usize> Matcher<Vec<String, Global>> for ContainerEqMatcher<[&str; N]>