Trait TestAll

Source
pub trait TestAll<Pred>: TupleLike {
    // Required method
    fn all(&self, predicate: Pred) -> bool;
}
Expand description

Tests if every element of the tuple matches a predicate.

§The unary predicate Pred

For testing Tuple<T0, T1, ... Tn>, you need to build a unary predicate, which needs to implement UnaryPredicate<T0>, and the NextUnaryPredicate needs to implement UnaryPredicate<T1>, and so on.

See the documentation page of UnaryPredicate for details.

Required Methods§

Source

fn all(&self, predicate: Pred) -> bool

Tests if every element of the tuple matches a predicate.

Check out UnaryPredicate’s documentation page to learn how to build a unary predicate that can be passed to all().

all() is short-circuiting; in other words, it will stop processing as soon as it finds a false, given that no matter what else happens, the result will also be false.

An empty tuple returns true.

Hint: The TupleLike trait provides the all() method as the wrapper for this all() method.

§Example
use tuplez::{tuple, TupleLike, unary_pred};

let predicate = unary_pred! {
    |x: i32| { (0..10).contains(x) },
    |x: &str| { x.parse::<i32>().is_ok() },
};

let tup = tuple!(1, 2, "3");
let result = tup.all(predicate);
assert_eq!(result, true);

let tup = tuple!(7, 8, "hello");
let result = tup.all(predicate);
assert_eq!(result, false);

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<Pred> TestAll<Pred> for Unit

Source§

impl<Pred, First, Other> TestAll<Pred> for Tuple<First, Other>
where for<'a> Pred: UnaryPredicate<'a, First>, for<'a> Other: TestAll<<Pred as UnaryPredicate<'a, First>>::NextUnaryPredicate>,