Struct tor_basic_utils::iter::FilterCount
source · 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: usize
The number of items that the filter considered and accepted.
n_rejected: usize
The 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 copy of the value. Read more
1.0.0 · source§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
source§fn eq(&self, other: &FilterCount) -> bool
fn eq(&self, other: &FilterCount) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.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
Mutably borrows from an owned value. Read more