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: Clone + Eq + Hash + Send + 'static> Intern<T>
[src]
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 HashMap
protected by a Mutex
.
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> PartialEq for Intern<T>
[src]
fn eq(&self, other: &Intern<T>) -> bool
[src]
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]
This method tests for !=
.
impl<T> Eq for Intern<T>
[src]
impl<T> Clone for Intern<T>
[src]
fn clone(&self) -> Self
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
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> Send for Intern<T>
[src]
impl<T> Sync for Intern<T>
[src]
impl<T> Borrow<T> for Intern<T>
[src]
impl<T> AsRef<T> for Intern<T>
[src]
impl<T> Deref for Intern<T>
[src]
type Target = T
The resulting type after dereferencing.
fn deref(&self) -> &T
[src]
Dereferences the value.
impl<T: Default + Hash + Eq + Clone + Send + 'static> Default for Intern<T>
[src]
impl<T: Debug> Debug for Intern<T>
[src]
fn fmt(&self, f: &mut Formatter) -> Result<(), Error>
[src]
Formats the value using the given formatter.
impl<T: Display> Display for Intern<T>
[src]
fn fmt(&self, f: &mut Formatter) -> Result<(), Error>
[src]
Formats the value using the given formatter. Read more
impl<T> Pointer for Intern<T>
[src]
fn fmt(&self, f: &mut Formatter) -> Result<(), Error>
[src]
Formats the value using the given formatter.
impl<T: Debug> Fits64 for Intern<T>
[src]
unsafe fn from_u64(x: u64) -> Self
[src]
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]
Convert to a u64
. This should be infallible.
fn test_fits64(self) -> bool
[src]
verify that the conversion is lossless
impl<T> Hash for Intern<T>
[src]
The hash implementation for Intern
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 pointer of
Intern::new(data)
with data
itself.