pub struct ById<T: ?Sized + Id>(pub T);
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§
impl<T: Copy + ?Sized + Id> Copy for ById<T>
impl<T: ?Sized + Id> Eq for ById<T>
Auto Trait Implementations§
impl<T> Freeze for ById<T>
impl<T> RefUnwindSafe for ById<T>where
T: RefUnwindSafe + ?Sized,
impl<T> Send for ById<T>
impl<T> Sync for ById<T>
impl<T> Unpin for ById<T>
impl<T> UnwindSafe for ById<T>where
T: UnwindSafe + ?Sized,
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