Skip to main content

assert_any

Macro assert_any 

Source
macro_rules! assert_any {
    ($collection:expr, $predicate:expr $(,)?) => { ... };
    ($collection:expr, $predicate:expr, $($message:tt)+) => { ... };
}
Expand description

Assert an 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_any!(a.iter(), |&x| x > 0);

// This will panic
let a = [1, 2, 3];
assert_any!(a.iter(), |&x| x > 3);
// assertion failed: `assert_any!(collection, predicate)`
// https://docs.rs/assertables/…/assertables/macro.assert_any.html
//  collection label: `a.iter()`,
//  collection debug: `Iter([1, 2, 3])`,
//         predicate: `|&x| x > 3`

This implementation uses ::std::iter::Iterator.

§Module macros