pub struct RefCmp<T: Same>(pub T);
Expand description
Wrapper for types to make their equality operations compare pointers.
This wrapper turns Same
into PartialEq
and RefHash
into Hash
.
It is mainly useful for storing unique objects in hash sets and similar
data structures.
§Example
use same::RefCmp;
use std::rc::Rc;
use std::collections::HashSet;
let a = ::std::sync::Arc::new(42);
let a_cloned = a.clone();
let b = ::std::sync::Arc::new(42);
let mut hash_set = ::std::collections::HashSet::new();
assert!(hash_set.insert(RefCmp(a)));
// a_cloned points to the same object as a...
assert!(!hash_set.insert(RefCmp(a_cloned)));
// but `b` doesn't, even though it has same value.
assert!(hash_set.insert(RefCmp(b)));
Tuple Fields§
§0: T
Trait Implementations§
impl<T: Same> Eq for RefCmp<T>
Auto Trait Implementations§
impl<T> Freeze for RefCmp<T>where
T: Freeze,
impl<T> RefUnwindSafe for RefCmp<T>where
T: RefUnwindSafe,
impl<T> Send for RefCmp<T>where
T: Send,
impl<T> Sync for RefCmp<T>where
T: Sync,
impl<T> Unpin for RefCmp<T>where
T: Unpin,
impl<T> UnwindSafe for RefCmp<T>where
T: UnwindSafe,
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