Struct internment::Intern
source · pub struct Intern<T: 'static + ?Sized> { /* private fields */ }
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§
source§impl<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
.
source§impl<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§
source§impl<T: 'static + ?Sized> DeepSizeOf for Intern<T>
impl<T: 'static + ?Sized> DeepSizeOf for Intern<T>
source§fn deep_size_of_children(&self, _context: &mut Context) -> usize
fn deep_size_of_children(&self, _context: &mut Context) -> usize
source§fn deep_size_of(&self) -> usize
fn deep_size_of(&self) -> usize
source§impl<'de, T: Eq + Hash + Send + Sync + ?Sized + 'static + Deserialize<'de>> Deserialize<'de> for Intern<T>
Available on crate feature serde
only.
impl<'de, T: Eq + Hash + Send + Sync + ?Sized + 'static + Deserialize<'de>> Deserialize<'de> for Intern<T>
serde
only.source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
source§impl<T: Debug> Fits64 for Intern<T>
Available 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.
source§impl<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]>
source§impl<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.
source§impl<T: Eq + Hash + Send + Sync + Ord + ?Sized> Ord for Intern<T>
impl<T: Eq + Hash + Send + Sync + Ord + ?Sized> Ord for Intern<T>
source§impl<T: Eq + Hash + Send + Sync + ?Sized> PartialEq for Intern<T>
impl<T: Eq + Hash + Send + Sync + ?Sized> PartialEq for Intern<T>
source§impl<T: Eq + Hash + Send + Sync + PartialOrd + ?Sized> PartialOrd for Intern<T>
impl<T: Eq + Hash + Send + Sync + PartialOrd + ?Sized> PartialOrd for Intern<T>
source§impl<T: Eq + Hash + Send + Sync + Serialize + ?Sized> Serialize for Intern<T>
Available on crate feature serde
only.
impl<T: Eq + Hash + Send + Sync + Serialize + ?Sized> 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
.