Struct internment::Intern
source · [−]pub struct Intern<T: 'static> { /* private fields */ }
Expand description
A pointer to an interned object that has been leaked and may be used in any thread without locking.
Implementations
sourceimpl<T: Eq + Hash + Send + Sync + 'static> Intern<T>
impl<T: Eq + Hash + Send + Sync + 'static> Intern<T>
sourcepub fn new(val: T) -> Intern<T>
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
.
sourcepub fn from<'a, Q: ?Sized + Eq + Hash + 'a>(val: &'a Q) -> Intern<T> where
T: Borrow<Q> + From<&'a Q>,
pub fn from<'a, Q: ?Sized + Eq + Hash + 'a>(val: &'a Q) -> Intern<T> where
T: Borrow<Q> + From<&'a Q>,
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)
.
sourcepub fn as_ref(self) -> &'static T
pub fn as_ref(self) -> &'static T
Get a long-lived reference to the data pointed to by an Intern
, which
is never freed from the intern pool.
sourcepub fn num_objects_interned() -> usize
pub fn num_objects_interned() -> usize
See how many objects have been interned. This may be helpful in analyzing memory use.
Trait Implementations
sourceimpl<T> Hash for Intern<T>
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.
sourceimpl<T: Ord> Ord for Intern<T>
impl<T: Ord> Ord for Intern<T>
sourceimpl<T: PartialOrd> PartialOrd<Intern<T>> for Intern<T>
impl<T: PartialOrd> PartialOrd<Intern<T>> for Intern<T>
sourcefn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
sourcefn lt(&self, other: &Self) -> bool
fn lt(&self, other: &Self) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
sourcefn le(&self, other: &Self) -> bool
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
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> Eq for Intern<T>
Auto Trait Implementations
impl<T> RefUnwindSafe for Intern<T> where
T: RefUnwindSafe,
impl<T> Send for Intern<T> where
T: Sync,
impl<T> Sync for Intern<T> where
T: Sync,
impl<T> Unpin for Intern<T>
impl<T> UnwindSafe for Intern<T> where
T: RefUnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> CallHasher for T where
T: Hash + ?Sized,
impl<T> CallHasher for T where
T: Hash + ?Sized,
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more