[−][src]Struct hashable_rc::HashableRc
A hashable wrapper around the [Rc<T>
] type.
A hash of a [HashableRc<T>
] is taken from the underlying pointer.
Therefore, two separate objects that may be considered equal will,
when contained in a [HashableRc<T>
], almost always have different
hashed values. For example, the following holds:
use std::collections::hash_map::DefaultHasher; use std::hash::{Hash, Hasher}; use std::rc::Rc; use hashable_rc::HashableRc; fn hash<H: Hash>(value: &H) -> u64 { let mut state = DefaultHasher::new(); value.hash(&mut state); state.finish() } // While the underlying values are considered equal, the hash values // will be different, due to being separate allocated objects with // different underlying pointers. let rc1 = Rc::new(42); let rc2 = Rc::new(42); // The hashes of the two reference countings are different. assert_ne!(hash(&HashableRc::new(rc1.clone())), hash(&HashableRc::new(rc2.clone()))); // Contrastingly, the hashes of clone reference countings pointing to // the same object are the equal. assert_eq!(hash(&HashableRc::new(rc1.clone())), hash(&HashableRc::new(rc1.clone())));
Similarly, equality of [HashableRc<T>
] objects is done by
evaluating pointer equality (using
ptr_eq()
).
The equality is not from the value itself, but from the pointer.
use std::rc::Rc; use hashable_rc::HashableRc; // Again, the values contained are equal, but the underlying pointers // are different. let rc1 = Rc::new(42); let rc2 = Rc::new(42); // Therefore, two HashableRc wrappers containing these reference // counters are not equal. assert_ne!(HashableRc::new(rc1.clone()), HashableRc::new(rc2.clone())); // But HashableRc holding the same underlying object are equal. assert_eq!(HashableRc::new(rc1.clone()), HashableRc::new(rc1.clone()));
Implementations
impl<T> HashableRc<T>
[src]
Trait Implementations
impl<T: Debug> Debug for HashableRc<T>
[src]
impl<T: Eq> Eq for HashableRc<T>
[src]
impl<T> Hash for HashableRc<T>
[src]
fn hash<H>(&self, state: &mut H) where
H: Hasher,
[src]
H: Hasher,
Generate a hash value for the [HashableRc<T>
].
This hash value is based on the underlying pointer. Two unique objects will most likely have different hashes, even if their values are the same.
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<T> PartialEq<HashableRc<T>> for HashableRc<T>
[src]
fn eq(&self, other: &Self) -> bool
[src]
Equality for two [HashableRc<T>
] objects.
Equality is determined by pointer equality, rather than value equality. Objects are only considered equal if they point to the same object.
#[must_use]fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<T> StructuralEq for HashableRc<T>
[src]
Auto Trait Implementations
impl<T> !RefUnwindSafe for HashableRc<T>
impl<T> !Send for HashableRc<T>
impl<T> !Sync for HashableRc<T>
impl<T> Unpin for HashableRc<T>
impl<T> UnwindSafe for HashableRc<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,