pub trait Expectation<S: ?Sized, D> {
// Required methods
fn test(&mut self, subject: &S) -> bool;
fn message(
&self,
expression: &Expression<'_>,
actual: &S,
inverted: bool,
representation: &D,
format: &DiffFormat,
) -> String;
}Expand description
An expectation defines a test for a property of the asserted subject.
It requires two methods: a test() method and a message() method.
The test() method is called to verify whether an actual subject meets the
expected property. In case the test of the expectation fails, the
message() method is called to form an expectation-specific failure
message.
Required Methods§
Sourcefn test(&mut self, subject: &S) -> bool
fn test(&mut self, subject: &S) -> bool
Verifies whether the actual subject fulfills the expected property.
Sourcefn message(
&self,
expression: &Expression<'_>,
actual: &S,
inverted: bool,
representation: &D,
format: &DiffFormat,
) -> String
fn message( &self, expression: &Expression<'_>, actual: &S, inverted: bool, representation: &D, format: &DiffFormat, ) -> String
Forms a failure message for this expectation.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
impl<D> Expectation<&char, D> for IsAlphabetic
impl<D> Expectation<&char, D> for IsAlphanumeric
impl<D> Expectation<&char, D> for IsAscii
impl<D> Expectation<&char, D> for IsControlChar
impl<D> Expectation<&char, D> for IsDigit
impl<D> Expectation<&char, D> for IsLowerCase
impl<D> Expectation<&char, D> for IsUpperCase
impl<D> Expectation<&char, D> for IsWhitespace
impl<D> Expectation<Date, D> for IsCloseTo<Date, TemporalMargin>
Available on crate feature
jiff only.impl<D> Expectation<Date, D> for IsCloseTo<Date, TemporalMargin>
Available on crate feature
time only.impl<D> Expectation<DateTime, D> for IsCloseTo<DateTime, TemporalMargin>
Available on crate feature
jiff only.impl<D> Expectation<NaiveDate, D> for IsCloseTo<NaiveDate, TemporalMargin>
Available on crate feature
chrono only.impl<D> Expectation<NaiveDateTime, D> for IsCloseTo<NaiveDateTime, TemporalMargin>
Available on crate feature
chrono only.impl<D> Expectation<NaiveTime, D> for IsCloseTo<NaiveTime, TemporalMargin>
Available on crate feature
chrono only.impl<D> Expectation<OffsetDateTime, D> for IsCloseTo<OffsetDateTime, TemporalMargin>
Available on crate feature
time only.impl<D> Expectation<PlainDateTime, D> for IsCloseTo<PlainDateTime, TemporalMargin>
Available on crate feature
time only.impl<D> Expectation<Time, D> for IsCloseTo<Time, TemporalMargin>
Available on crate feature
jiff only.impl<D> Expectation<Time, D> for IsCloseTo<Time, TemporalMargin>
Available on crate feature
time only.impl<D> Expectation<Timestamp, D> for IsCloseTo<Timestamp, TemporalMargin>
Available on crate feature
jiff only.impl<D> Expectation<Timestamp, D> for IsCloseTo<Timestamp, TemporalMargin>
Available on crate feature
time only.impl<D> Expectation<Zoned, D> for IsCloseTo<Zoned, TemporalMargin>
Available on crate feature
jiff only.impl<D> Expectation<bool, D> for IsFalse
impl<D> Expectation<bool, D> for IsTrue
impl<D> Expectation<char, D> for IsAlphabetic
impl<D> Expectation<char, D> for IsAlphanumeric
impl<D> Expectation<char, D> for IsAscii
impl<D> Expectation<char, D> for IsControlChar
impl<D> Expectation<char, D> for IsDigit
impl<D> Expectation<char, D> for IsLowerCase
impl<D> Expectation<char, D> for IsUpperCase
impl<D> Expectation<char, D> for IsWhitespace
impl<D> Expectation<f32, D> for IsCloseTo<f32, F32Margin>
Available on crate feature
float-cmp only.impl<D> Expectation<f64, D> for IsCloseTo<f64, F64Margin>
Available on crate feature
float-cmp only.impl<M, E, D> Expectation<M, D> for MapContainsExactlyKeys<E>where
M: MapProperties,
<M as MapProperties>::Key: PartialEq<E>,
D: Represent<E> + Represent<<M as MapProperties>::Key> + Represent<<M as MapProperties>::Value>,
impl<M, E, D> Expectation<M, D> for MapContainsKey<E>where
M: MapProperties,
<M as MapProperties>::Key: PartialEq<E>,
D: Represent<E> + Represent<<M as MapProperties>::Key> + Represent<<M as MapProperties>::Value>,
impl<M, E, D> Expectation<M, D> for MapContainsKeys<E>where
M: MapProperties,
<M as MapProperties>::Key: PartialEq<E>,
D: Represent<E> + Represent<<M as MapProperties>::Key> + Represent<<M as MapProperties>::Value>,
impl<M, E, D> Expectation<M, D> for MapContainsValue<E>where
M: MapProperties,
<M as MapProperties>::Value: PartialEq<E>,
D: Represent<E> + Represent<<M as MapProperties>::Key> + Represent<<M as MapProperties>::Value>,
impl<M, E, D> Expectation<M, D> for MapContainsValues<E>where
M: MapProperties,
<M as MapProperties>::Value: PartialEq<E>,
D: Represent<E> + Represent<<M as MapProperties>::Key> + Represent<<M as MapProperties>::Value>,
impl<M, E, D> Expectation<M, D> for MapDoesNotContainKeys<E>where
M: MapProperties,
<M as MapProperties>::Key: PartialEq<E>,
D: Represent<E> + Represent<<M as MapProperties>::Key> + Represent<<M as MapProperties>::Value>,
impl<M, E, D> Expectation<M, D> for MapDoesNotContainValues<E>where
M: MapProperties,
<M as MapProperties>::Value: PartialEq<E>,
D: Represent<E> + Represent<<M as MapProperties>::Key> + Represent<<M as MapProperties>::Value>,
impl<S, D, A1: Expectation<S, D>, A2: Expectation<S, D>, A3: Expectation<S, D>, A4: Expectation<S, D>, A5: Expectation<S, D>, A6: Expectation<S, D>, A7: Expectation<S, D>, A8: Expectation<S, D>, A9: Expectation<S, D>, A10: Expectation<S, D>, A11: Expectation<S, D>, A12: Expectation<S, D>> Expectation<S, D> for All<(Rec<A1>, Rec<A2>, Rec<A3>, Rec<A4>, Rec<A5>, Rec<A6>, Rec<A7>, Rec<A8>, Rec<A9>, Rec<A10>, Rec<A11>, Rec<A12>)>
impl<S, D, A1: Expectation<S, D>, A2: Expectation<S, D>, A3: Expectation<S, D>, A4: Expectation<S, D>, A5: Expectation<S, D>, A6: Expectation<S, D>, A7: Expectation<S, D>, A8: Expectation<S, D>, A9: Expectation<S, D>, A10: Expectation<S, D>, A11: Expectation<S, D>, A12: Expectation<S, D>> Expectation<S, D> for Any<(Rec<A1>, Rec<A2>, Rec<A3>, Rec<A4>, Rec<A5>, Rec<A6>, Rec<A7>, Rec<A8>, Rec<A9>, Rec<A10>, Rec<A11>, Rec<A12>)>
impl<S, D, A1: Expectation<S, D>, A2: Expectation<S, D>, A3: Expectation<S, D>, A4: Expectation<S, D>, A5: Expectation<S, D>, A6: Expectation<S, D>, A7: Expectation<S, D>, A8: Expectation<S, D>, A9: Expectation<S, D>, A10: Expectation<S, D>, A11: Expectation<S, D>> Expectation<S, D> for All<(Rec<A1>, Rec<A2>, Rec<A3>, Rec<A4>, Rec<A5>, Rec<A6>, Rec<A7>, Rec<A8>, Rec<A9>, Rec<A10>, Rec<A11>)>
impl<S, D, A1: Expectation<S, D>, A2: Expectation<S, D>, A3: Expectation<S, D>, A4: Expectation<S, D>, A5: Expectation<S, D>, A6: Expectation<S, D>, A7: Expectation<S, D>, A8: Expectation<S, D>, A9: Expectation<S, D>, A10: Expectation<S, D>, A11: Expectation<S, D>> Expectation<S, D> for Any<(Rec<A1>, Rec<A2>, Rec<A3>, Rec<A4>, Rec<A5>, Rec<A6>, Rec<A7>, Rec<A8>, Rec<A9>, Rec<A10>, Rec<A11>)>
impl<S, D, A1: Expectation<S, D>, A2: Expectation<S, D>, A3: Expectation<S, D>, A4: Expectation<S, D>, A5: Expectation<S, D>, A6: Expectation<S, D>, A7: Expectation<S, D>, A8: Expectation<S, D>, A9: Expectation<S, D>, A10: Expectation<S, D>> Expectation<S, D> for All<(Rec<A1>, Rec<A2>, Rec<A3>, Rec<A4>, Rec<A5>, Rec<A6>, Rec<A7>, Rec<A8>, Rec<A9>, Rec<A10>)>
impl<S, D, A1: Expectation<S, D>, A2: Expectation<S, D>, A3: Expectation<S, D>, A4: Expectation<S, D>, A5: Expectation<S, D>, A6: Expectation<S, D>, A7: Expectation<S, D>, A8: Expectation<S, D>, A9: Expectation<S, D>, A10: Expectation<S, D>> Expectation<S, D> for Any<(Rec<A1>, Rec<A2>, Rec<A3>, Rec<A4>, Rec<A5>, Rec<A6>, Rec<A7>, Rec<A8>, Rec<A9>, Rec<A10>)>
impl<S, D, A1: Expectation<S, D>, A2: Expectation<S, D>, A3: Expectation<S, D>, A4: Expectation<S, D>, A5: Expectation<S, D>, A6: Expectation<S, D>, A7: Expectation<S, D>, A8: Expectation<S, D>, A9: Expectation<S, D>> Expectation<S, D> for All<(Rec<A1>, Rec<A2>, Rec<A3>, Rec<A4>, Rec<A5>, Rec<A6>, Rec<A7>, Rec<A8>, Rec<A9>)>
impl<S, D, A1: Expectation<S, D>, A2: Expectation<S, D>, A3: Expectation<S, D>, A4: Expectation<S, D>, A5: Expectation<S, D>, A6: Expectation<S, D>, A7: Expectation<S, D>, A8: Expectation<S, D>, A9: Expectation<S, D>> Expectation<S, D> for Any<(Rec<A1>, Rec<A2>, Rec<A3>, Rec<A4>, Rec<A5>, Rec<A6>, Rec<A7>, Rec<A8>, Rec<A9>)>
impl<S, D, A1: Expectation<S, D>, A2: Expectation<S, D>, A3: Expectation<S, D>, A4: Expectation<S, D>, A5: Expectation<S, D>, A6: Expectation<S, D>, A7: Expectation<S, D>, A8: Expectation<S, D>> Expectation<S, D> for All<(Rec<A1>, Rec<A2>, Rec<A3>, Rec<A4>, Rec<A5>, Rec<A6>, Rec<A7>, Rec<A8>)>
impl<S, D, A1: Expectation<S, D>, A2: Expectation<S, D>, A3: Expectation<S, D>, A4: Expectation<S, D>, A5: Expectation<S, D>, A6: Expectation<S, D>, A7: Expectation<S, D>, A8: Expectation<S, D>> Expectation<S, D> for Any<(Rec<A1>, Rec<A2>, Rec<A3>, Rec<A4>, Rec<A5>, Rec<A6>, Rec<A7>, Rec<A8>)>
impl<S, D, A1: Expectation<S, D>, A2: Expectation<S, D>, A3: Expectation<S, D>, A4: Expectation<S, D>, A5: Expectation<S, D>, A6: Expectation<S, D>, A7: Expectation<S, D>> Expectation<S, D> for All<(Rec<A1>, Rec<A2>, Rec<A3>, Rec<A4>, Rec<A5>, Rec<A6>, Rec<A7>)>
impl<S, D, A1: Expectation<S, D>, A2: Expectation<S, D>, A3: Expectation<S, D>, A4: Expectation<S, D>, A5: Expectation<S, D>, A6: Expectation<S, D>, A7: Expectation<S, D>> Expectation<S, D> for Any<(Rec<A1>, Rec<A2>, Rec<A3>, Rec<A4>, Rec<A5>, Rec<A6>, Rec<A7>)>
impl<S, D, A1: Expectation<S, D>, A2: Expectation<S, D>, A3: Expectation<S, D>, A4: Expectation<S, D>, A5: Expectation<S, D>, A6: Expectation<S, D>> Expectation<S, D> for All<(Rec<A1>, Rec<A2>, Rec<A3>, Rec<A4>, Rec<A5>, Rec<A6>)>
impl<S, D, A1: Expectation<S, D>, A2: Expectation<S, D>, A3: Expectation<S, D>, A4: Expectation<S, D>, A5: Expectation<S, D>, A6: Expectation<S, D>> Expectation<S, D> for Any<(Rec<A1>, Rec<A2>, Rec<A3>, Rec<A4>, Rec<A5>, Rec<A6>)>
impl<S, D, A1: Expectation<S, D>, A2: Expectation<S, D>, A3: Expectation<S, D>, A4: Expectation<S, D>, A5: Expectation<S, D>> Expectation<S, D> for All<(Rec<A1>, Rec<A2>, Rec<A3>, Rec<A4>, Rec<A5>)>
impl<S, D, A1: Expectation<S, D>, A2: Expectation<S, D>, A3: Expectation<S, D>, A4: Expectation<S, D>, A5: Expectation<S, D>> Expectation<S, D> for Any<(Rec<A1>, Rec<A2>, Rec<A3>, Rec<A4>, Rec<A5>)>
impl<S, D, A1: Expectation<S, D>, A2: Expectation<S, D>, A3: Expectation<S, D>, A4: Expectation<S, D>> Expectation<S, D> for All<(Rec<A1>, Rec<A2>, Rec<A3>, Rec<A4>)>
impl<S, D, A1: Expectation<S, D>, A2: Expectation<S, D>, A3: Expectation<S, D>, A4: Expectation<S, D>> Expectation<S, D> for Any<(Rec<A1>, Rec<A2>, Rec<A3>, Rec<A4>)>
impl<S, D, A1: Expectation<S, D>, A2: Expectation<S, D>, A3: Expectation<S, D>> Expectation<S, D> for All<(Rec<A1>, Rec<A2>, Rec<A3>)>
impl<S, D, A1: Expectation<S, D>, A2: Expectation<S, D>, A3: Expectation<S, D>> Expectation<S, D> for Any<(Rec<A1>, Rec<A2>, Rec<A3>)>
impl<S, D, A1: Expectation<S, D>, A2: Expectation<S, D>> Expectation<S, D> for All<(Rec<A1>, Rec<A2>)>
impl<S, D, A1: Expectation<S, D>, A2: Expectation<S, D>> Expectation<S, D> for Any<(Rec<A1>, Rec<A2>)>
impl<S, D, A1: Expectation<S, D>> Expectation<S, D> for All<(Rec<A1>,)>
impl<S, D, A1: Expectation<S, D>> Expectation<S, D> for Any<(Rec<A1>,)>
impl<S, D, E> Expectation<S, D> for IsEqualTo<E>
impl<S, D, R> Expectation<S, D> for HasCharCountInRange<R, usize>
impl<S, D, const N: usize> Expectation<S, D> for StringContainsAnyOf<&[char; N]>
impl<S, D, const N: usize> Expectation<S, D> for StringContainsAnyOf<[char; N]>
impl<S, D> Expectation<Code<S>, D> for DoesNotPanicwhere
S: FnOnce(),
Available on crate feature
panic only.impl<S, D> Expectation<Code<S>, D> for DoesPanicwhere
S: FnOnce(),
Available on crate feature
panic only.impl<S, D> Expectation<S, D> for ErrorHasSource
impl<S, D> Expectation<S, D> for ErrorHasSourceMessage
impl<S, D> Expectation<S, D> for HasAtLeastCharCount<usize>
impl<S, D> Expectation<S, D> for HasAtLeastLength<usize>
impl<S, D> Expectation<S, D> for HasAtMostCharCount<usize>
impl<S, D> Expectation<S, D> for HasAtMostLength<usize>
impl<S, D> Expectation<S, D> for HasCharCount<usize>
impl<S, D> Expectation<S, D> for HasCharCountGreaterThan<usize>
impl<S, D> Expectation<S, D> for HasCharCountLessThan<usize>
impl<S, D> Expectation<S, D> for HasLength<usize>
impl<S, D> Expectation<S, D> for HasLengthGreaterThan<usize>
impl<S, D> Expectation<S, D> for HasLengthLessThan<usize>
impl<S, D> Expectation<S, D> for HasPrecisionOf
impl<S, D> Expectation<S, D> for HasScaleOf
impl<S, D> Expectation<S, D> for IsANumberwhere
S: IsNanProperty,
D: Represent<S>,
impl<S, D> Expectation<S, D> for IsEmptywhere
S: IsEmptyProperty,
D: Represent<S>,
impl<S, D> Expectation<S, D> for IsFinitewhere
S: InfinityProperty,
D: Represent<S>,
impl<S, D> Expectation<S, D> for IsInfinitewhere
S: InfinityProperty,
D: Represent<S>,
impl<S, D> Expectation<S, D> for IsIntegerwhere
S: DecimalProperties,
D: Represent<S>,
impl<S, D> Expectation<S, D> for IsNegativewhere
S: SignumProperty,
D: Represent<S>,
impl<S, D> Expectation<S, D> for IsOne
impl<S, D> Expectation<S, D> for IsPositivewhere
S: SignumProperty,
D: Represent<S>,
impl<S, D> Expectation<S, D> for IsSameAs<S>
impl<S, D> Expectation<S, D> for IsZero
impl<S, D> Expectation<S, D> for StringContains<&str>
impl<S, D> Expectation<S, D> for StringContains<String>
impl<S, D> Expectation<S, D> for StringContains<char>
impl<S, D> Expectation<S, D> for StringContainsAnyOf<&[char]>
impl<S, D> Expectation<S, D> for StringEndsWith<&str>
impl<S, D> Expectation<S, D> for StringEndsWith<String>
impl<S, D> Expectation<S, D> for StringEndsWith<char>
impl<S, D> Expectation<S, D> for StringMatches<'_>
Available on crate feature
regex only.impl<S, D> Expectation<S, D> for StringStartsWith<&str>
impl<S, D> Expectation<S, D> for StringStartsWith<String>
impl<S, D> Expectation<S, D> for StringStartsWith<char>
impl<S, E, D, R> Expectation<S, D> for IsInRange<R, E>where
S: PartialOrd<E>,
E: PartialOrd<S>,
R: RangeBounds<E>,
D: Represent<S> + Represent<E> + Represent<R>,
impl<S, E, D> Expectation<S, D> for HasDebugString<E>
impl<S, E, D> Expectation<S, D> for HasDisplayString<E>
impl<S, E, D> Expectation<S, D> for IsAfter<E>
impl<S, E, D> Expectation<S, D> for IsAtLeast<E>
impl<S, E, D> Expectation<S, D> for IsAtMost<E>
impl<S, E, D> Expectation<S, D> for IsBefore<E>
impl<S, E, D> Expectation<S, D> for IsBetween<E>
impl<S, E, D> Expectation<S, D> for IsGreaterThan<E>
impl<S, E, D> Expectation<S, D> for IsIn<E>
impl<S, E, D> Expectation<S, D> for IsLessThan<E>
impl<S, E, D> Expectation<S, D> for Not<E>where
E: Invertible + Expectation<S, D>,
impl<S, E, D> Expectation<S, D> for Rec<E>where
E: Expectation<S, D>,
impl<S, P, D> Expectation<S, D> for Predicate<P>
impl<S, R, D> Expectation<S, D> for HasLengthInRange<R, usize>
impl<T, D> Expectation<&Option<T>, D> for IsNonewhere
D: Represent<T>,
impl<T, D> Expectation<&Option<T>, D> for IsSomewhere
D: Represent<T>,
impl<T, D> Expectation<Option<T>, D> for IsNonewhere
D: Represent<T>,
impl<T, D> Expectation<Option<T>, D> for IsSomewhere
D: Represent<T>,
impl<T, D> Expectation<Vec<T>, D> for HasAtLeastNumberOfElementswhere
D: Represent<T>,
impl<T, D> Expectation<Vec<T>, D> for HasSingleElementwhere
D: Represent<T>,
impl<T, E, D> Expectation<&Option<T>, D> for HasValue<E>
impl<T, E, D> Expectation<&Result<T, E>, D> for IsErr
impl<T, E, D> Expectation<&Result<T, E>, D> for IsOk
impl<T, E, D> Expectation<Option<T>, D> for HasValue<E>
impl<T, E, D> Expectation<Result<T, E>, D> for IsErr
impl<T, E, D> Expectation<Result<T, E>, D> for IsOk
impl<T, E, D> Expectation<Vec<T>, D> for IteratorContains<E>
impl<T, E, D> Expectation<Vec<T>, D> for IteratorContainsAllInOrder<E>
impl<T, E, D> Expectation<Vec<T>, D> for IteratorContainsAllOf<E>
impl<T, E, D> Expectation<Vec<T>, D> for IteratorContainsAnyOf<E>
impl<T, E, D> Expectation<Vec<T>, D> for IteratorContainsExactly<E>
impl<T, E, D> Expectation<Vec<T>, D> for IteratorContainsExactlyInAnyOrder<E>
impl<T, E, D> Expectation<Vec<T>, D> for IteratorContainsOnly<E>
impl<T, E, D> Expectation<Vec<T>, D> for IteratorContainsOnlyOnce<E>
impl<T, E, D> Expectation<Vec<T>, D> for IteratorContainsSequence<E>
impl<T, E, D> Expectation<Vec<T>, D> for IteratorEndsWith<E>
impl<T, E, D> Expectation<Vec<T>, D> for IteratorStartsWith<E>
impl<T, E, X, D> Expectation<&Result<T, E>, D> for HasError<X>
impl<T, E, X, D> Expectation<&Result<T, E>, D> for HasValue<X>
impl<T, E, X, D> Expectation<Result<T, E>, D> for HasError<X>
impl<T, E, X, D> Expectation<Result<T, E>, D> for HasValue<X>
impl<T, P, D> Expectation<Vec<T>, D> for AllSatisfy<P>
impl<T, P, D> Expectation<Vec<T>, D> for AnySatisfies<P>
impl<T, P, D> Expectation<Vec<T>, D> for NoneSatisfies<P>
impl<TZ1, TZ2, D> Expectation<DateTime<TZ1>, D> for IsCloseTo<DateTime<TZ2>, TemporalMargin>
Available on crate feature
chrono only.