[][src]Struct internment::Intern

pub struct Intern<T> { /* fields omitted */ }

A pointer to an interned object.

The interned object will be held in memory indefinitely. On the plus side, this means that lifetime issues are simple when using Intern.

Example

use internment::Intern;

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

Example with owned String data

use internment::Intern;

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

Implementations

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

pub fn new(val: T) -> Intern<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 Intern::new is a bit slow, since it needs to check a HashSet protected by a Mutex.

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

Intern a value from a reference.

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.

Trait Implementations

impl<T> AsRef<T> for Intern<T>[src]

impl<T> Borrow<T> for Intern<T>[src]

impl<T> Clone for Intern<T>[src]

impl<T> Copy for Intern<T>[src]

An Intern is Copy, which is unusal for a pointer. This is safe because we never free the data pointed to by an Intern.

impl<T: Debug> Debug for Intern<T>[src]

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

impl<T> Deref for Intern<T>[src]

type Target = T

The resulting type after dereferencing.

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

impl<T: Display> Display for Intern<T>[src]

impl<T> Eq for Intern<T>[src]

impl<T: Debug> Fits64 for Intern<T>[src]

The Fits64 implementation for Intern<T> is designed to normally give (relatively) small numbers, by XORing with a fixed pointer that is also on the heap. This should make the most significant bits of the resulting u64 be zero, which will mean that Set64 (which is space-efficient in storing small integers) can store this result in fewer than 8 bytes.

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

impl<T> Hash for Intern<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: Ord> Ord for Intern<T>[src]

impl<T> PartialEq<Intern<T>> for Intern<T>[src]

impl<T: PartialOrd> PartialOrd<Intern<T>> for Intern<T>[src]

impl<T> Pointer for Intern<T>[src]

impl<T> Send for Intern<T>[src]

impl<T: Serialize> Serialize for Intern<T>[src]

impl<T> Sync for Intern<T>[src]

Auto Trait Implementations

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

impl<T> Unpin for Intern<T>

impl<T> UnwindSafe for Intern<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>,