pub struct FilterCount {
pub n_accepted: usize,
pub n_rejected: usize,
}Expand description
A record of how many items a CountingFilter returned by
IteratorExt::filter_cnt accepted and rejected.
In tor-guardmgr we use this type to keep track of which filters reject which guards.
Fields§
§n_accepted: usizeThe number of items that the filter considered and accepted.
n_rejected: usizeThe number of items that the filter considered and accepted.
Implementations§
Source§impl FilterCount
impl FilterCount
Sourcepub fn display_frac_rejected(&self) -> DisplayFracRejected<'_>
pub fn display_frac_rejected(&self) -> DisplayFracRejected<'_>
Return a wrapper that can be displayed as the fraction of rejected items.
§Example
let mut count = FilterCount::default();
let sum_of_evens : u32 = (1..=10)
.filter_cnt(&mut count, |x| *x % 2 == 0)
.sum();
assert_eq!(format!("Rejected {} as odd", count.display_frac_rejected()),
"Rejected 5/10 as odd".to_string());Sourcepub fn count(&mut self, accept: bool) -> bool
pub fn count(&mut self, accept: bool) -> bool
Count and return the provided boolean value.
This is an alternative way to use FilterCount when you have to provide
a function that takes a predicate rather than a member of an iterator
chain.
§Example
let mut count = FilterCount::default();
let mut emoji = "Hello 🙂 World 🌏!".to_string();
emoji.retain(|ch| count.count(!ch.is_ascii()));
assert_eq!(emoji, "🙂🌏");
assert_eq!(count, FilterCount { n_accepted: 2, n_rejected: 14});Trait Implementations§
Source§impl Clone for FilterCount
impl Clone for FilterCount
Source§fn clone(&self) -> FilterCount
fn clone(&self) -> FilterCount
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for FilterCount
impl Debug for FilterCount
Source§impl Default for FilterCount
impl Default for FilterCount
Source§fn default() -> FilterCount
fn default() -> FilterCount
Source§impl PartialEq for FilterCount
impl PartialEq for FilterCount
impl Copy for FilterCount
impl Eq for FilterCount
impl StructuralPartialEq for FilterCount
Auto Trait Implementations§
impl Freeze for FilterCount
impl RefUnwindSafe for FilterCount
impl Send for FilterCount
impl Sync for FilterCount
impl Unpin for FilterCount
impl UnwindSafe for FilterCount
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreLayout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 16 bytes