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>

source

pub fn describe<'a>( &self, doc: &'a BoxAllocator ) -> DocBuilder<'a, BoxAllocator>

source

pub fn falsify<'d>( &self, t: &T, doc: &'d BoxAllocator ) -> Option<DocBuilder<'d, BoxAllocator>>

Provide a minimized falsification of the predicate, if possible

source

pub fn satisfied<'t>(&self, t: &'t T) -> bool

source

pub fn assert_satisfied(&self, t: &T) -> Result<(), DebugString>

source

pub fn and(self, rhs: Predicate<T>) -> Predicate<T>

source

pub fn or(self, rhs: Predicate<T>) -> Predicate<T>

source

pub fn not(self) -> Predicate<T>

source

pub fn predicate<F, S>(f: F, label: S) -> Predicate<T>
where F: for<'t> Fn(&'t T) -> bool + Send + Sync + 'static, S: Into<String>,

Construct a simple predicate function

source§

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

pub fn equal(t: T) -> Predicate<T>

Construct a Predicate that expects two Ts to be equal

source

pub fn not_equal(t: T) -> Predicate<T>

Construct a Predicate that expects two Ts to be non-equal

source§

impl<Elem, T> Predicate<T>
where T: Send + Sync + 'static, for<'a> &'a T: IntoIterator<Item = &'a Elem>, Elem: Debug + Send + Sync + 'static,

Predicates on iterable types, those convertible into iterators via IntoIterator (e.g. Vec<_>)

source

pub fn all(pred: Predicate<Elem>) -> Predicate<T>

Construct a predicate that all elements of an iterable type match a given predicate If the iterable is empty, the predicate will succeed

source

pub fn any(pred: Predicate<Elem>) -> Predicate<T>

Construct a predicate that at least one element of an iterable type match a given predicate If the iterable is empty, the predicate will fail

source§

impl<'e, Elem, Iter> Predicate<Iter>
where Iter: Iterator<Item = &'e Elem> + Clone, Elem: Debug + Send + Sync + 'static,

Predicates on types which are an Iterator

source

pub fn iter_all(pred: Predicate<Elem>) -> Predicate<Iter>

Construct a predicate that all elements of an Iterator match a given predicate If the Iterator is empty, the predicate will succeed

source

pub fn iter_any(pred: Predicate<Elem>) -> Predicate<Iter>

Construct a predicate that at least one element of an Iterator match a given predicate If the iterator is empty, the predicate will fail

source§

impl<U: Send + Sync + 'static> Predicate<U>

source

pub fn over<F, T, P>(self, project: F, path: P) -> Predicate<T>
where F: Fn(&T) -> &U + Send + Sync + 'static, P: Into<String>, T: 'static,

Lift a predicate over a projection from T -> &U. This constructs a Predicate from a predicate on some field (or arbitrary projection) of type U.

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.

source

pub fn over_value<F, T, P>(self, project: F, path: P) -> Predicate<T>
where F: Fn(&T) -> U + Send + Sync + 'static, P: Into<String>, T: 'static,

Lift a predicate over a projection from T -> U. This constructs a Predicate from a predicate on some field (or arbitrary projection) of type U.

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§

source§

impl<T> Clone for Predicate<T>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T> Debug for Predicate<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T: 'static, Elem: Debug + 'static> IsAll<T> for Predicate<Elem>
where for<'a> &'a T: IntoIterator<Item = &'a Elem>,

source§

fn describe<'d>(&self, doc: &'d BoxAllocator) -> DocBuilder<'d, BoxAllocator>

source§

fn falsify_all<'d>( &self, t: &T, doc: &'d BoxAllocator ) -> Option<DocBuilder<'d, BoxAllocator>>

source§

impl<T: 'static, Elem: Debug + 'static> IsAny<T> for Predicate<Elem>
where for<'a> &'a T: IntoIterator<Item = &'a Elem>,

source§

fn describe<'d>(&self, doc: &'d BoxAllocator) -> DocBuilder<'d, BoxAllocator>

source§

fn falsify_any<'d>( &self, t: &T, doc: &'d BoxAllocator ) -> Option<DocBuilder<'d, BoxAllocator>>

Auto Trait Implementations§

§

impl<T> Freeze for Predicate<T>

§

impl<T> !RefUnwindSafe for Predicate<T>

§

impl<T> Send for Predicate<T>
where T: Sync + Send,

§

impl<T> Sync for Predicate<T>
where T: Sync + Send,

§

impl<T> Unpin for Predicate<T>

§

impl<T> !UnwindSafe for Predicate<T>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> DebugExt for T
where T: Debug,

source§

fn debug(&self) -> String

§

impl<T> Encode<Ambiguous1> for T

§

unsafe fn encode( self, _encoder: &mut Encoder<'_>, _offset: usize, _depth: Depth ) -> Result<(), Error>

Encodes the object into the encoder’s buffers. Any handles stored in the object are swapped for Handle::INVALID. Read more
§

impl<T> Encode<Ambiguous2> for T

§

unsafe fn encode( self, _encoder: &mut Encoder<'_>, _offset: usize, _depth: Depth ) -> Result<(), Error>

Encodes the object into the encoder’s buffers. Any handles stored in the object are swapped for Handle::INVALID. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more