IteratorExt

Trait IteratorExt 

Source
pub trait IteratorExt: Iterator {
    // Provided method
    fn filter_cnt<P>(
        self,
        count: &mut FilterCount,
        pred: P,
    ) -> CountingFilter<'_, P, Self> โ“˜
       where Self: Sized,
             P: FnMut(&Self::Item) -> bool { ... }
}
Expand description

Iterator extension trait to implement a counting filter.

Provided Methodsยง

Source

fn filter_cnt<P>( self, count: &mut FilterCount, pred: P, ) -> CountingFilter<'_, P, Self> โ“˜
where Self: Sized, P: FnMut(&Self::Item) -> bool,

Return an iterator that contains every member of this iterator, and which records its progress in count.

The values in count are initially set to zero. Then, every time the filter considers an item, it will either increment count.n_accepted or count.n_rejected.

Note that if the iterator is dropped before it is exhausted, the count will not be complete.

ยงExamples
use tor_basic_utils::iter::{IteratorExt, FilterCount};

let mut count = FilterCount::default();
let emoji : String = "Hello ๐Ÿ™‚ World ๐ŸŒ!"
    .chars()
    .filter_cnt(&mut count, |ch| !ch.is_ascii())
    .collect();
assert_eq!(emoji, "๐Ÿ™‚๐ŸŒ");
assert_eq!(count, FilterCount { n_accepted: 2, n_rejected: 14});

Implementorsยง

Sourceยง

impl<I> IteratorExt for I
where I: Iterator,