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> PartialEq for RefCmp<T>
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<T: Same + RefHash> Hash for RefCmp<T>
[src]

Feeds this value into the given [Hasher]. Read more

Feeds a slice of this type into the given [Hasher]. Read more

impl<T: Same> Deref for RefCmp<T>
[src]

The resulting type after dereferencing.

Dereferences the value.

impl<U, T: Same + AsRef<U>> AsRef<U> for RefCmp<T>
[src]

Performs the conversion.

impl<T: Same> Borrow<T> for RefCmp<T>
[src]

Immutably borrows from an owned value. Read more

Auto Trait Implementations

impl<T> Send for RefCmp<T> where
    T: Send

impl<T> Sync for RefCmp<T> where
    T: Sync