Struct internment::LocalIntern[][src]

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

A pointer to a thread-local interned object.

The interned object will be held in memory as long as the thread is still running. Thus you can arrange a crude sort of arena allocation by running code using LocalIntern on a temporary thread. Lifetime issues are as simple as when using Intern. LocalIntern differs in that it is neigher Send nor Share, so it cannot be used in a multithreaded manner. On the benefit side, it is faster than Intern, and the memory can be freed (by running in a temporary thread).

Example

use internment::LocalIntern;

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

Methods

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

Intern a value in a thread-local way. 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 LocalIntern::new is a bit slow, since it needs to check a HashMap protected by a Mutex.

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

Trait Implementations

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

The Fits64 implementation for LocalIntern<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.

Convert back from a u64. This is unsafe, since it is only infallible (and lossless) if the u64 originally came from type Self. Read more

Convert to a u64. This should be infallible.

verify that the conversion is lossless

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

Important traits for &'a mut R

Performs the conversion.

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

Important traits for &'a mut R

Immutably borrows from an owned value. Read more

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

The resulting type after dereferencing.

Important traits for &'a mut R

Dereferences the value.

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

Formats the value using the given formatter. Read more

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

Formats the value using the given formatter.

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

Performs the conversion.

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

Returns the "default value" for a type. Read more

impl<T> Hash for LocalIntern<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.

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

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

impl<T> PartialEq for LocalIntern<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> Eq for LocalIntern<T>
[src]

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

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl<T: Ord> Ord for LocalIntern<T>
[src]

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

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

Serialize this value into the given Serde serializer. Read more

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

Deserialize this value from the given Serde deserializer. Read more

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

Formats the value using the given formatter. Read more

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

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

An LocalIntern is Copy, which is unusal for a pointer. This is safe because we never free the data pointed to by an LocalIntern until the thread itself is destroyed.

Auto Trait Implementations

impl<T> !Send for LocalIntern<T>

impl<T> !Sync for LocalIntern<T>