Struct same::RefCmp [−][src]
pub struct RefCmp<T: Same>(pub T);
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)));
Trait Implementations
impl<T: Same> Eq for RefCmp<T>
[src]
impl<T: Same> Eq for RefCmp<T>
impl<T: Same> PartialEq for RefCmp<T>
[src]
impl<T: Same> PartialEq for RefCmp<T>
fn eq(&self, other: &Self) -> bool
[src]
fn eq(&self, other: &Self) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
fn ne(&self, other: &Rhs) -> bool
1.0.0
[src]This method tests for !=
.
impl<T: Same + RefHash> Hash for RefCmp<T>
[src]
impl<T: Same + RefHash> Hash for RefCmp<T>
fn hash<H: Hasher>(&self, hasher: &mut H)
[src]
fn hash<H: Hasher>(&self, hasher: &mut H)
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0
[src]Feeds a slice of this type into the given [Hasher
]. Read more
impl<T: Same> Deref for RefCmp<T>
[src]
impl<T: Same> Deref for RefCmp<T>
type Target = T
The resulting type after dereferencing.
fn deref(&self) -> &Self::Target
[src]
fn deref(&self) -> &Self::Target
Dereferences the value.
impl<U, T: Same + AsRef<U>> AsRef<U> for RefCmp<T>
[src]
impl<U, T: Same + AsRef<U>> AsRef<U> for RefCmp<T>
impl<T: Same> Borrow<T> for RefCmp<T>
[src]
impl<T: Same> Borrow<T> for RefCmp<T>