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§
Sourcefn describe(&self, matcher_result: MatcherResult) -> Description
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 ()
impl Describable for ()
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
impl<I0: Describable, I1: Describable, I2: Describable, I3: Describable, I4: Describable, I5: Describable, I6: Describable> Describable for (I0, I1, I2, I3, I4, I5, I6)
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)
impl<I0: Describable, I1: Describable, I2: Describable, I3: Describable, I4: Describable, I5: Describable> Describable for (I0, I1, I2, I3, I4, I5)
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)
impl<I0: Describable, I1: Describable, I2: Describable, I3: Describable, I4: Describable> Describable for (I0, I1, I2, I3, I4)
fn describe(&self, matcher_result: MatcherResult) -> Description
Source§impl<I0: Describable, I1: Describable, I2: Describable, I3: Describable> Describable for (I0, I1, I2, I3)
impl<I0: Describable, I1: Describable, I2: Describable, I3: Describable> Describable for (I0, I1, I2, I3)
fn describe(&self, matcher_result: MatcherResult) -> Description
Source§impl<I0: Describable, I1: Describable, I2: Describable> Describable for (I0, I1, I2)
impl<I0: Describable, I1: Describable, I2: Describable> Describable for (I0, I1, I2)
fn describe(&self, matcher_result: MatcherResult) -> Description
Source§impl<I0: Describable, I1: Describable> Describable for (I0, I1)
impl<I0: Describable, I1: Describable> Describable for (I0, I1)
fn describe(&self, matcher_result: MatcherResult) -> Description
Source§impl<I0: Describable> Describable for (I0,)
impl<I0: Describable> Describable for (I0,)
fn describe(&self, matcher_result: MatcherResult) -> Description
Implementors§
impl<'matchers, T: Debug, ContainerT: ?Sized, ModeT> Describable for ContainerContainsUnorderedMatcher<'matchers, ContainerT, T, ModeT>
impl<ExpectedContainerT: Debug, Mode> Describable for ContainerEqMatcher<ExpectedContainerT, Mode>
impl<ExpectedT: Deref<Target = str>> Describable for StrMatcher<ExpectedT>
impl<InnerMatcher: Describable> Describable for DisplayMatcher<InnerMatcher>
impl<InnerMatcherT: Describable, ModeT> Describable for ContainsMatcher<InnerMatcherT, ModeT>
impl<T: Debug, P, D1: PredicateDescription, D2: PredicateDescription> Describable for PredicateMatcher<T, P, D1, D2>
impl<T: Debug> Describable for NearMatcher<T>
num-traits only.