fuchsia_bluetooth::expectation

Enum Predicate

Source
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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

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

Source§

fn debug(&self) -> String

§

impl<T, D> Encode<Ambiguous1, D> for T
where D: ResourceDialect,

§

unsafe fn encode( self, _encoder: &mut Encoder<'_, D>, _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, D> Encode<Ambiguous2, D> for T
where D: ResourceDialect,

§

unsafe fn encode( self, _encoder: &mut Encoder<'_, D>, _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,

Source§

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>,

Source§

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>,

Source§

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