[][src]Struct internment::ArcIntern

pub struct ArcIntern<T: Eq + Hash + Send + 'static> { /* fields omitted */ }

A pointer to a reference-counted interned object.

The interned object will be held in memory only until its reference count reaches zero.

Example

use internment::ArcIntern;

let x = ArcIntern::new("hello");
let y = ArcIntern::new("world");
assert_ne!(x, y);
assert_eq!(x, ArcIntern::new("hello"));
assert_eq!(*x, "hello"); // dereference an ArcIntern like a pointer

Example with owned String data

use internment::ArcIntern;

let x = ArcIntern::new("hello".to_string());
let y = ArcIntern::<String>::from("world");
assert_ne!(x, y);
assert_eq!(x, ArcIntern::from("hello"));
assert_eq!(&*x, "hello"); // dereference an ArcIntern like a pointer

Implementations

impl<T: Eq + Hash + Send + 'static> ArcIntern<T>[src]

pub fn new(val: T) -> ArcIntern<T>[src]

Intern a value. If this value has not previously been interned, then new will allocate a spot for the value on the heap. Otherwise, it will return a pointer to the object previously allocated.

Note that ArcIntern::new is a bit slow, since it needs to check a HashMap protected by a Mutex.

pub fn from<'a, Q: ?Sized + Eq + Hash + 'a>(val: &'a Q) -> ArcIntern<T> where
    T: Borrow<Q> + From<&'a Q>, 
[src]

Intern a value from a reference with atomic reference counting.

If this value has not previously been interned, then new will allocate a spot for the value on the heap and generate that value using T::from(val).

pub fn num_objects_interned(&self) -> usize[src]

See how many objects have been interned. This may be helpful in analyzing memory use.

pub fn refcount(&self) -> usize[src]

Return the number of counts for this pointer.

Trait Implementations

impl<T: Send + Hash + Eq> AsRef<T> for ArcIntern<T>[src]

impl<T: Eq + Hash + Send> Borrow<T> for ArcIntern<T>[src]

impl<T: Eq + Hash + Send + 'static> Clone for ArcIntern<T>[src]

impl<T: Eq + Hash + Send + Debug> Debug for ArcIntern<T>[src]

impl<T: Eq + Hash + Send + Default + 'static> Default for ArcIntern<T>[src]

impl<T: Eq + Hash + Send> Deref for ArcIntern<T>[src]

type Target = T

The resulting type after dereferencing.

impl<'de, T: Eq + Hash + Send + 'static + Deserialize<'de>> Deserialize<'de> for ArcIntern<T>[src]

impl<T: Eq + Hash + Send + Display> Display for ArcIntern<T>[src]

impl<T: Eq + Hash + Send> Drop for ArcIntern<T>[src]

impl<T: Eq + Hash + Send> Eq for ArcIntern<T>[src]

impl<T: Eq + Hash + Send + 'static> From<T> for ArcIntern<T>[src]

impl<T: Eq + Hash + Send> Hash for ArcIntern<T>[src]

The hash implementation returns the hash of the pointer value, not the hash of the value pointed to. This should be irrelevant, since there is a unique pointer for every value, but it is observable, since you could compare the hash of the pointer with hash of the data itself.

impl<T: Eq + Hash + Send + Ord> Ord for ArcIntern<T>[src]

impl<T: Eq + Hash + Send> PartialEq<ArcIntern<T>> for ArcIntern<T>[src]

impl<T: Eq + Hash + Send + PartialOrd> PartialOrd<ArcIntern<T>> for ArcIntern<T>[src]

impl<T: Eq + Hash + Send> Pointer for ArcIntern<T>[src]

impl<T: Eq + Hash + Send> Send for ArcIntern<T>[src]

impl<T: Eq + Hash + Send + Serialize> Serialize for ArcIntern<T>[src]

impl<T: Eq + Hash + Send + Sync> Sync for ArcIntern<T>[src]

Auto Trait Implementations

impl<T> RefUnwindSafe for ArcIntern<T> where
    T: RefUnwindSafe

impl<T> Unpin for ArcIntern<T>

impl<T> UnwindSafe for ArcIntern<T> where
    T: RefUnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T> From<!> for T[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,