[][src]Macro totems::assert_all

macro_rules! assert_all {
    ($collection:expr, $predicate:expr) => { ... };
    ($collection:expr, $predicate:expr, $($arg:tt)+) => { ... };
}

Asserts that all items in a collection match a predicate.

Parameters

  • &collection A reference to a collection.
  • predicate A closure or function that takes an item and returns a boolean.
  • description (optional) A string describing the predicate.

Dependencies

Example

use totems::assert_all;
let vec = vec![1, 3, 5, 7, 9, 11, 13, 15, 17, 19];
assert_all!(&vec, |&x| x > 0, "all > 0");

Example Error Messages

thread 'main' panicked at 'assertion failed: (all elements of collection match predicate)
  predicate: all < 0
 collection: [-1, 3, 5, 7, 9, 11, 13, 15, 17, 19]
', src/collections.rs:165:9