iterator_assertions/lib.rs
1use core::ops::Not;
2
3pub trait IteratorAssert {
4 #[must_use]
5 fn assert(self, assertion: fn(&Self) -> bool) -> Self;
6}
7
8impl<I> IteratorAssert for I
9where
10 I: IntoIterator,
11{
12 fn assert(self, assertion: fn(&Self) -> bool) -> Self {
13 if (assertion)(&self).not() {
14 panic!("iterator assertion did not hold");
15 }
16 self
17 }
18}