Skip to main content

Describable

Trait Describable 

Source
pub trait Describable {
    // Required method
    fn describe(&self, matcher_result: MatcherResult) -> Description;
}
Expand description

An item, normally a Matcher with positive and negative valences which can be turned into a Description for human consumption.

Required Methods§

Source

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

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.

The output appears next to Expected in an assertion failure message. For example:

Value of: ...
Expected: is equal to 7
          ^^^^^^^^^^^^^
Actual: ...

When the matcher contains one or more inner matchers, the implementation should invoke Self::describe on the inner matchers to complete the description. It should place the inner description at a point where a verb phrase would fit. For example, the matcher some implements describe as follows:

fn describe(&self, matcher_result: MatcherResult) -> Description {
    match matcher_result {
        MatcherResult::Matches => {
            Description::new()
                .text("has a value which")
                .nested(self.inner.describe(MatcherResult::Matches))
      // Inner matcher: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        }
        MatcherResult::DoesNotMatch => {...} // Similar to the above
    }
}

The output expectation differs from that of explain_match in that it is a verb phrase (beginning with a verb like “is”) rather than a relative clause (beginning with “which” or “whose”). This difference is because the output of explain_match is always used adjectivally to describe the actual value, while describe is used in contexts where a relative clause would not make sense.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementations on Foreign Types§

Source§

impl Describable for ()

Source§

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

Source§

impl<I0: Describable, I1: Describable, I2: Describable, I3: Describable, I4: Describable, I5: Describable, I6: Describable, I7: Describable, I8: Describable, I9: Describable, I10: Describable, I11: Describable> Describable for (I0, I1, I2, I3, I4, I5, I6, I7, I8, I9, I10, I11)

Source§

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

Source§

impl<I0: Describable, I1: Describable, I2: Describable, I3: Describable, I4: Describable, I5: Describable, I6: Describable, I7: Describable, I8: Describable, I9: Describable, I10: Describable> Describable for (I0, I1, I2, I3, I4, I5, I6, I7, I8, I9, I10)

Source§

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

Source§

impl<I0: Describable, I1: Describable, I2: Describable, I3: Describable, I4: Describable, I5: Describable, I6: Describable, I7: Describable, I8: Describable, I9: Describable> Describable for (I0, I1, I2, I3, I4, I5, I6, I7, I8, I9)

Source§

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

Source§

impl<I0: Describable, I1: Describable, I2: Describable, I3: Describable, I4: Describable, I5: Describable, I6: Describable, I7: Describable, I8: Describable> Describable for (I0, I1, I2, I3, I4, I5, I6, I7, I8)

Source§

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

Source§

impl<I0: Describable, I1: Describable, I2: Describable, I3: Describable, I4: Describable, I5: Describable, I6: Describable, I7: Describable> Describable for (I0, I1, I2, I3, I4, I5, I6, I7)

Source§

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

Source§

impl<I0: Describable, I1: Describable, I2: Describable, I3: Describable, I4: Describable, I5: Describable, I6: Describable> Describable for (I0, I1, I2, I3, I4, I5, I6)

Source§

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

Source§

impl<I0: Describable, I1: Describable, I2: Describable, I3: Describable, I4: Describable, I5: Describable> Describable for (I0, I1, I2, I3, I4, I5)

Source§

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

Source§

impl<I0: Describable, I1: Describable, I2: Describable, I3: Describable, I4: Describable> Describable for (I0, I1, I2, I3, I4)

Source§

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

Source§

impl<I0: Describable, I1: Describable, I2: Describable, I3: Describable> Describable for (I0, I1, I2, I3)

Source§

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

Source§

impl<I0: Describable, I1: Describable, I2: Describable> Describable for (I0, I1, I2)

Source§

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

Source§

impl<I0: Describable, I1: Describable> Describable for (I0, I1)

Source§

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

Source§

impl<I0: Describable> Describable for (I0,)

Source§

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

Implementors§

Source§

impl<'matchers, T: Debug, ContainerT: ?Sized, ModeT> Describable for ContainerContainsUnorderedMatcher<'matchers, ContainerT, T, ModeT>

Source§

impl<ExpectedContainerT: Debug, Mode> Describable for ContainerEqMatcher<ExpectedContainerT, Mode>

Source§

impl<ExpectedT: Deref<Target = str>> Describable for StrMatcher<ExpectedT>

Source§

impl<InnerMatcher: Describable> Describable for DisplayMatcher<InnerMatcher>

Source§

impl<InnerMatcherT: Describable, ModeT> Describable for ContainsMatcher<InnerMatcherT, ModeT>

Source§

impl<T: Debug, P, D1: PredicateDescription, D2: PredicateDescription> Describable for PredicateMatcher<T, P, D1, D2>

Source§

impl<T: Debug> Describable for NearMatcher<T>

Available on crate feature num-traits only.