Struct refid::ById [−][src]
Expand description
Newtype for references (or other types that implement Id
) where equality is
defined by the same
method of the Id
trait
Example
use refid::ById;
use std::collections::HashSet;
fn count_distinct<T>(slice: &[&T]) -> usize {
let mut counted: HashSet<ById<&T>> = HashSet::new();
let mut count: usize = 0;
for item in slice {
if counted.insert(ById(item)) {
count += 1;
}
}
count
}
let v1 = "X".to_string();
let v2 = "X".to_string();
let v3 = "X".to_string();
assert_eq!(count_distinct(&vec![&v1, &v2, &v1, &v3]), 3);
Tuple Fields
0: T
inner value (reference or other type that implements Id
)
Trait Implementations
Auto Trait Implementations
impl<T: ?Sized> RefUnwindSafe for ById<T> where
T: RefUnwindSafe,
impl<T: ?Sized> UnwindSafe for ById<T> where
T: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more