Struct internment::Intern
source · [−]pub struct Intern<T: 'static + ?Sized> { /* private fields */ }
intern
only.Expand description
A pointer to an interned object
An Intern
points to an 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
.
sourceimpl<T: Eq + Hash + Send + Sync + 'static + ?Sized> Intern<T>
impl<T: Eq + Hash + Send + Sync + 'static + ?Sized> Intern<T>
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.
sourcepub fn benchmarking_only_clear_interns()
pub fn benchmarking_only_clear_interns()
Only for benchmarking, this will cause problems
Trait Implementations
sourceimpl<'de, T: Eq + Hash + Send + Sync + 'static + Deserialize<'de>> Deserialize<'de> for Intern<T>
This is supported on crate feature serde
only.
impl<'de, T: Eq + Hash + Send + Sync + 'static + Deserialize<'de>> Deserialize<'de> for Intern<T>
serde
only.sourcefn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Deserialize this value from the given Serde deserializer. Read more
sourceimpl<T: Debug> Fits64 for Intern<T>
This is supported on crate feature tinyset
only.
impl<T: Debug> Fits64 for Intern<T>
tinyset
only.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. The pointer is also divided by its alignment to eliminate those
redundant insignificant zeros. 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 far
fewer than 8 bytes.
sourceimpl<T: Eq + Hash + Send + Sync + 'static + Copy, const N: usize> From<&'_ [T; N]> for Intern<[T]>
impl<T: Eq + Hash + Send + Sync + 'static + Copy, const N: usize> From<&'_ [T; N]> for Intern<[T]>
sourceimpl<T: Eq + Hash + Send + Sync + ?Sized> Hash for Intern<T>
impl<T: Eq + Hash + Send + Sync + ?Sized> 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: Eq + Hash + Send + Sync + Ord + ?Sized> Ord for Intern<T>
impl<T: Eq + Hash + Send + Sync + Ord + ?Sized> Ord for Intern<T>
sourceimpl<T: Eq + Hash + Send + Sync + PartialOrd + ?Sized> PartialOrd<Intern<T>> for Intern<T>
impl<T: Eq + Hash + Send + Sync + PartialOrd + ?Sized> 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
sourceimpl<T: Eq + Hash + Send + Sync + Serialize> Serialize for Intern<T>
This is supported on crate feature serde
only.
impl<T: Eq + Hash + Send + Sync + Serialize> Serialize for Intern<T>
serde
only.impl<T: ?Sized> 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 + Hash + Send + Sync + ?Sized> Eq for Intern<T>
Auto Trait Implementations
impl<T: ?Sized> RefUnwindSafe for Intern<T> where
T: RefUnwindSafe,
impl<T: ?Sized> Send for Intern<T> where
T: Sync,
impl<T: ?Sized> Sync for Intern<T> where
T: Sync,
impl<T: ?Sized> Unpin for Intern<T>
impl<T: ?Sized> 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