macro_rules! assert_all {
($collection:expr, $predicate:expr $(,)?) => { ... };
($collection:expr, $predicate:expr, $($message:tt)+) => { ... };
}Expand description
Assert every element of the iterator matches a predicate.
Pseudocode:
collection into iter ∀ predicate
-
If true, return
(). -
Otherwise, call
panic!with a message and the values of the expressions with their debug representations.
§Examples
use assertables::*;
let a = [1, 2, 3];
assert_all!(a.into_iter(), |x: i8| x > 0);
// This will panic
let a = [1, -2, 3];
assert_all!(a.into_iter(), |x: i8| x > 0);
// assertion failed: `assert_all!(collection, predicate)`
// https://docs.rs/assertables/…/assertables/macro.assert_all.html
// collection label: `a.into_iter()`,
// collection debug: `IntoIter([1, -2, 3])`,
// predicate: `|x: i8| x > 0`This implementation uses ::std::iter::Iterator.