Struct internment::Intern [−][src]
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
Methods
impl<T: Eq + Hash + Send + 'static> Intern<T>
[src]
impl<T: Eq + Hash + Send + 'static> Intern<T>
pub fn new(val: T) -> Intern<T>
[src]
pub fn new(val: T) -> Intern<T>
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 num_objects_interned(&self) -> usize
[src]
pub fn num_objects_interned(&self) -> usize
See how many objects have been interned. This may be helpful in analyzing memory use.
Trait Implementations
impl<T> Clone for Intern<T>
[src]
impl<T> Clone for Intern<T>
fn clone(&self) -> Self
[src]
fn clone(&self) -> Self
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl<T> Copy for Intern<T>
[src]
impl<T> Copy for Intern<T>
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> Send for Intern<T>
[src]
impl<T> Send for Intern<T>
impl<T> Sync for Intern<T>
[src]
impl<T> Sync for Intern<T>
impl<T: Debug> Fits64 for Intern<T>
[src]
impl<T: Debug> Fits64 for Intern<T>
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.
unsafe fn from_u64(x: u64) -> Self
[src]
unsafe fn from_u64(x: u64) -> Self
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
fn to_u64(self) -> u64
[src]
fn to_u64(self) -> u64
Convert to a u64
. This should be infallible.
fn test_fits64(self) -> bool
[src]
fn test_fits64(self) -> bool
verify that the conversion is lossless
impl<T> AsRef<T> for Intern<T>
[src]
impl<T> AsRef<T> for Intern<T>
impl<T> Borrow<T> for Intern<T>
[src]
impl<T> Borrow<T> for Intern<T>
ⓘImportant traits for &'a mut Rfn borrow(&self) -> &T
[src]
fn borrow(&self) -> &T
Immutably borrows from an owned value. Read more
impl<T> Deref for Intern<T>
[src]
impl<T> Deref for Intern<T>
type Target = T
The resulting type after dereferencing.
ⓘImportant traits for &'a mut Rfn deref(&self) -> &T
[src]
fn deref(&self) -> &T
Dereferences the value.
impl<T: Display> Display for Intern<T>
[src]
impl<T: Display> Display for Intern<T>
fn fmt(&self, f: &mut Formatter) -> Result<(), Error>
[src]
fn fmt(&self, f: &mut Formatter) -> Result<(), Error>
Formats the value using the given formatter. Read more
impl<T> Pointer for Intern<T>
[src]
impl<T> Pointer for Intern<T>
fn fmt(&self, f: &mut Formatter) -> Result<(), Error>
[src]
fn fmt(&self, f: &mut Formatter) -> Result<(), Error>
Formats the value using the given formatter.
impl<T: Eq + Hash + Send + 'static> From<T> for Intern<T>
[src]
impl<T: Eq + Hash + Send + 'static> From<T> for Intern<T>
impl<T: Eq + Hash + Send + Default + 'static> Default for Intern<T>
[src]
impl<T: Eq + Hash + Send + Default + 'static> Default for Intern<T>
impl<T> Hash for Intern<T>
[src]
impl<T> Hash for Intern<T>
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.
fn hash<H: Hasher>(&self, state: &mut H)
[src]
fn hash<H: Hasher>(&self, state: &mut H)
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl<T> PartialEq for Intern<T>
[src]
impl<T> PartialEq for Intern<T>
fn eq(&self, other: &Intern<T>) -> bool
[src]
fn eq(&self, other: &Intern<T>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
fn ne(&self, other: &Rhs) -> bool
This method tests for !=
.
impl<T> Eq for Intern<T>
[src]
impl<T> Eq for Intern<T>
impl<T: PartialOrd> PartialOrd for Intern<T>
[src]
impl<T: PartialOrd> PartialOrd for Intern<T>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
[src]
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, other: &Self) -> bool
[src]
fn lt(&self, other: &Self) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, other: &Self) -> bool
[src]
fn le(&self, other: &Self) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, other: &Self) -> bool
[src]
fn gt(&self, other: &Self) -> bool
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, other: &Self) -> bool
[src]
fn ge(&self, other: &Self) -> bool
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 Intern<T>
[src]
impl<T: Ord> Ord for Intern<T>
fn cmp(&self, other: &Self) -> Ordering
[src]
fn cmp(&self, other: &Self) -> Ordering
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self
1.21.0[src]
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
impl<T: Serialize> Serialize for Intern<T>
[src]
impl<T: Serialize> Serialize for Intern<T>
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>
[src]
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>
Serialize this value into the given Serde serializer. Read more
impl<'de, T: Eq + Hash + Send + 'static + Deserialize<'de>> Deserialize<'de> for Intern<T>
[src]
impl<'de, T: Eq + Hash + Send + 'static + Deserialize<'de>> Deserialize<'de> for Intern<T>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
[src]
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Deserialize this value from the given Serde deserializer. Read more
impl<T: Debug> Debug for Intern<T>
[src]
impl<T: Debug> Debug for Intern<T>