traitful 0.3.0

A collection of helper macros for trait patterns
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use traitful::extend;

/// Extend the `Iterator` trait with new `all_eq()` method
#[extend(for<I: Iterator> I)]
pub trait IteratorExt: Iterator {
    /// Return true if all elements of the iterator are equal.
    fn all_eq(mut self) -> bool
    where
        Self::Item: PartialEq,
        Self: Sized,
    {
        let Some(first) = self.next() else {
            return true;
        };

        self.all(|x| x == first)
    }
}