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ยง
Sourcefn filter_cnt<P>(
self,
count: &mut FilterCount,
pred: P,
) -> CountingFilter<'_, P, Self> โ
fn filter_cnt<P>( self, count: &mut FilterCount, pred: P, ) -> CountingFilter<'_, P, Self> โ
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});