Skip to main content

Predicate

Trait Predicate 

Source
pub trait Predicate<T: ?Sized> {
    // Required methods
    fn check(value: &T) -> bool;
    fn expect(formatter: &mut Formatter<'_>) -> Result;
    fn expect_code(formatter: &mut Formatter<'_>) -> Result;

    // Provided method
    fn check_value(value: T) -> bool
       where T: Sized { ... }
}
Expand description

Represents predicates over values of type T.

Required Methods§

Source

fn check(value: &T) -> bool

Checks the given reference to value of type T.

Returns true if the predicate is satisfied by this value, false otherwise.

Source

fn expect(formatter: &mut Formatter<'_>) -> Result

Formats the expectation of this predicate into the given formatter.

§Errors

Returns fmt::Error in case formatting fails.

Source

fn expect_code(formatter: &mut Formatter<'_>) -> Result

Formats the expectation code of this predicate into the given formatter.

§Errors

Returns fmt::Error in case formatting fails.

Provided Methods§

Source

fn check_value(value: T) -> bool
where T: Sized,

Checks the given value of type T.

Returns true if the predicate is satisfied by this value, false otherwise.

The default implementation simply calls check with value reference.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T: ?Sized, P: Predicate<T> + ?Sized, Q: Predicate<T> + ?Sized> Predicate<T> for And<P, Q>

Source§

impl<T: ?Sized, P: Predicate<T> + ?Sized, Q: Predicate<T> + ?Sized> Predicate<T> for Or<P, Q>

Source§

impl<T: ?Sized, P: Predicate<T> + ?Sized, Q: Predicate<T> + ?Sized> Predicate<T> for Xor<P, Q>

Source§

impl<T: ?Sized, P: Predicate<T> + ?Sized> Predicate<T> for Not<P>

Source§

impl<T: ?Sized> Predicate<T> for False

Source§

impl<T: ?Sized> Predicate<T> for True