iterator-assertions 0.1.0

Assert something about an iterator in place.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use core::ops::Not;

pub trait IteratorAssert {
    #[must_use]
    fn assert(self, assertion: fn(&Self) -> bool) -> Self;
}

impl<I> IteratorAssert for I
where
    I: IntoIterator,
{
    fn assert(self, assertion: fn(&Self) -> bool) -> Self {
        if (assertion)(&self).not() {
            panic!("iterator assertion did not hold");
        }
        self
    }
}