pub enum Predicate<T> {
Equal(Arc<T>, Arc<dyn Fn(&T, &T) -> bool + Send + Sync + 'static>, Arc<dyn Fn(&T) -> String + Send + Sync + 'static>),
And(Box<Predicate<T>>, Box<Predicate<T>>),
Or(Box<Predicate<T>>, Box<Predicate<T>>),
Not(Box<Predicate<T>>),
Predicate(Arc<dyn Fn(&T) -> bool + Send + Sync>, String),
Over(Arc<dyn IsOver<T> + Send + Sync>),
Any(Arc<dyn IsAny<T> + Send + Sync + 'static>),
All(Arc<dyn IsAll<T> + Send + Sync + 'static>),
}
Expand description
A Boolean predicate on type T
. Predicate functions are a boolean algebra
just as raw boolean values are; they an be ANDed, ORed, NOTed. This allows
a clear and concise language for declaring test expectations.
Variants§
Equal(Arc<T>, Arc<dyn Fn(&T, &T) -> bool + Send + Sync + 'static>, Arc<dyn Fn(&T) -> String + Send + Sync + 'static>)
And(Box<Predicate<T>>, Box<Predicate<T>>)
Or(Box<Predicate<T>>, Box<Predicate<T>>)
Not(Box<Predicate<T>>)
Predicate(Arc<dyn Fn(&T) -> bool + Send + Sync>, String)
Over(Arc<dyn IsOver<T> + Send + Sync>)
Any(Arc<dyn IsAny<T> + Send + Sync + 'static>)
All(Arc<dyn IsAll<T> + Send + Sync + 'static>)
Implementations§
Source§impl<T> Predicate<T>
impl<T> Predicate<T>
pub fn describe<'a>( &self, doc: &'a BoxAllocator, ) -> DocBuilder<'a, BoxAllocator>
Sourcepub fn falsify<'d>(
&self,
t: &T,
doc: &'d BoxAllocator,
) -> Option<DocBuilder<'d, BoxAllocator>>
pub fn falsify<'d>( &self, t: &T, doc: &'d BoxAllocator, ) -> Option<DocBuilder<'d, BoxAllocator>>
Provide a minimized falsification of the predicate, if possible
pub fn satisfied<'t>(&self, t: &'t T) -> bool
pub fn assert_satisfied(&self, t: &T) -> Result<(), DebugString>
pub fn and(self, rhs: Predicate<T>) -> Predicate<T>
pub fn or(self, rhs: Predicate<T>) -> Predicate<T>
pub fn not(self) -> Predicate<T>
Source§impl<T: PartialEq + Debug + 'static> Predicate<T>
impl<T: PartialEq + Debug + 'static> Predicate<T>
Convenient implementations that rely on Debug
to provide output on falsification, and
PartialEq
to provide equality. If you wish to create predicates for ?Debug
types, use the
Predicate
or Equal
constructors directly.
Source§impl<Elem, T> Predicate<T>
impl<Elem, T> Predicate<T>
Predicates on iterable types, those convertible into iterators via IntoIterator (e.g. Vec<_>)
Source§impl<'e, Elem, Iter> Predicate<Iter>
impl<'e, Elem, Iter> Predicate<Iter>
Predicates on types which are an Iterator
Source§impl<U: Send + Sync + 'static> Predicate<U>
impl<U: Send + Sync + 'static> Predicate<U>
Sourcepub fn over<F, T, P>(self, project: F, path: P) -> Predicate<T>
pub fn over<F, T, P>(self, project: F, path: P) -> Predicate<T>
Lift a predicate over a projection from T -> &U
. This constructs a PredicateU
.
This allows:
- Creating a Predicate on a struct from a predicate on a field (or field of a field) of that struct.
- Creating a Predicate on a type from a predicate on some value computable from that type
Compared to writing an arbitrary function using the predicate()
method, an
over
projection allows for more minimal falsification and better error reporting in
failure cases.
Use over
when your projection function returns a reference. If you need to return a value
(for example, a temporary whose reference lifetime would not escape the function), use
over_value
.
Sourcepub fn over_value<F, T, P>(self, project: F, path: P) -> Predicate<T>
pub fn over_value<F, T, P>(self, project: F, path: P) -> Predicate<T>
Lift a predicate over a projection from T -> U
. This constructs a PredicateU
.
This allows:
- Creating a Predicate on a struct from a predicate on a field (or field of a field) of that struct.
- Creating a Predicate on a type from a predicate on some value computable from that type
Compared to writing an arbitrary function using the predicate()
method, an
over
projection allows for more minimal falsification and better error reporting in
failure cases.
Use over_value
when your projection function needs to return a value. If you can return a
reference, use over
.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Predicate<T>
impl<T> !RefUnwindSafe for Predicate<T>
impl<T> Send for Predicate<T>
impl<T> Sync for Predicate<T>
impl<T> Unpin for Predicate<T>
impl<T> !UnwindSafe for Predicate<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)