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
Returns a duplicate of the value. Read more
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
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
Returns the “default value” for a type. Read more
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§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
🔬This is a nightly-only experimental API. (
clone_to_uninit)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>
Converts
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>
Converts
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 more