Struct internment::ArcIntern
source · pub struct ArcIntern<T: ?Sized + Eq + Hash + Send + Sync + 'static> { /* private fields */ }
Expand description
A pointer to a reference-counted interned object.
This type requires feature “arc”. The interned object will be held in memory only until its reference count reaches zero.
§Example
use internment::ArcIntern;
let x = ArcIntern::new("hello");
let y = ArcIntern::new("world");
assert_ne!(x, y);
assert_eq!(x, ArcIntern::new("hello"));
assert_eq!(*x, "hello"); // dereference an ArcIntern like a pointer
§Example with owned String
data
use internment::ArcIntern;
let x = ArcIntern::new("hello".to_string());
let y = ArcIntern::<String>::from_ref("world");
assert_eq!(x, ArcIntern::from_ref("hello"));
assert_eq!(&*x, "hello"); // dereference an ArcIntern like a pointer
Implementations§
source§impl<T: ?Sized + Eq + Hash + Send + Sync + 'static> ArcIntern<T>
impl<T: ?Sized + Eq + Hash + Send + Sync + 'static> ArcIntern<T>
sourcepub fn from_ref<'a, Q: ?Sized + Eq + Hash + 'a>(val: &'a Q) -> ArcIntern<T>
pub fn from_ref<'a, Q: ?Sized + Eq + Hash + 'a>(val: &'a Q) -> ArcIntern<T>
Intern a value from a reference with atomic reference counting.
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 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
source§impl<T: Eq + Hash + Send + Sync + 'static> ArcIntern<T>
impl<T: Eq + Hash + Send + Sync + 'static> ArcIntern<T>
sourcepub fn new(val: T) -> ArcIntern<T>
pub fn new(val: T) -> ArcIntern<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 ArcIntern::new
is a bit slow, since it needs to check
a DashMap
which is protected by internal sharded locks.
Trait Implementations§
source§impl<T: ?Sized + Eq + Hash + Send + Sync + 'static> DeepSizeOf for ArcIntern<T>
impl<T: ?Sized + Eq + Hash + Send + Sync + 'static> DeepSizeOf for ArcIntern<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: 'a, 'a> Deserialize<'de> for ArcIntern<[u8]>
Available on crate feature serde
only.
impl<'de: 'a, 'a> Deserialize<'de> for ArcIntern<[u8]>
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<'de, T> Deserialize<'de> for ArcIntern<T>
Available on crate feature serde
only.
impl<'de, T> Deserialize<'de> for ArcIntern<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<'de: 'a, 'a> Deserialize<'de> for ArcIntern<str>
Available on crate feature serde
only.
impl<'de: 'a, 'a> Deserialize<'de> for ArcIntern<str>
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: ?Sized + Eq + Hash + Send + Sync> Hash for ArcIntern<T>
impl<T: ?Sized + Eq + Hash + Send + Sync> Hash for ArcIntern<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: ?Sized + Eq + Hash + Send + Sync + Ord> Ord for ArcIntern<T>
impl<T: ?Sized + Eq + Hash + Send + Sync + Ord> Ord for ArcIntern<T>
source§impl<'a, T: Copy + Send + Sync + Hash + Eq + 'static, const N: usize> PartialEq<&[T; N]> for ArcIntern<[T]>
impl<'a, T: Copy + Send + Sync + Hash + Eq + 'static, const N: usize> PartialEq<&[T; N]> for ArcIntern<[T]>
source§impl<'a, T: Copy + Send + Sync + Hash + Eq + 'static> PartialEq<&'a mut [T]> for ArcIntern<[T]>
impl<'a, T: Copy + Send + Sync + Hash + Eq + 'static> PartialEq<&'a mut [T]> for ArcIntern<[T]>
source§impl<'a, T: Copy + Send + Sync + Hash + Eq + 'static, const N: usize> PartialEq<[T; N]> for ArcIntern<[T]>
impl<'a, T: Copy + Send + Sync + Hash + Eq + 'static, const N: usize> PartialEq<[T; N]> for ArcIntern<[T]>
source§impl<'a, T: Copy + Send + Sync + Hash + Eq + 'static> PartialEq<Arc<[T]>> for ArcIntern<[T]>
impl<'a, T: Copy + Send + Sync + Hash + Eq + 'static> PartialEq<Arc<[T]>> for ArcIntern<[T]>
source§impl<'a> PartialEq<Arc<str>> for ArcIntern<str>
impl<'a> PartialEq<Arc<str>> for ArcIntern<str>
source§impl<'a, T: Copy + Send + Sync + Hash + Eq + 'static> PartialEq<ArcIntern<[T]>> for &'a [T]
impl<'a, T: Copy + Send + Sync + Hash + Eq + 'static> PartialEq<ArcIntern<[T]>> for &'a [T]
source§impl<'a, T: Copy + Send + Sync + Hash + Eq + 'static, const N: usize> PartialEq<ArcIntern<[T]>> for &[T; N]
impl<'a, T: Copy + Send + Sync + Hash + Eq + 'static, const N: usize> PartialEq<ArcIntern<[T]>> for &[T; N]
source§impl<'a, T: Copy + Send + Sync + Hash + Eq + 'static> PartialEq<ArcIntern<[T]>> for &'a mut [T]
impl<'a, T: Copy + Send + Sync + Hash + Eq + 'static> PartialEq<ArcIntern<[T]>> for &'a mut [T]
source§impl<'a, T: Copy + Send + Sync + Hash + Eq + 'static> PartialEq<ArcIntern<[T]>> for [T]
impl<'a, T: Copy + Send + Sync + Hash + Eq + 'static> PartialEq<ArcIntern<[T]>> for [T]
source§impl<'a, T: Copy + Send + Sync + Hash + Eq + 'static, const N: usize> PartialEq<ArcIntern<[T]>> for [T; N]
impl<'a, T: Copy + Send + Sync + Hash + Eq + 'static, const N: usize> PartialEq<ArcIntern<[T]>> for [T; N]
source§impl<'a, T: Copy + Send + Sync + Hash + Eq + 'static> PartialEq<ArcIntern<[T]>> for Arc<[T]>
impl<'a, T: Copy + Send + Sync + Hash + Eq + 'static> PartialEq<ArcIntern<[T]>> for Arc<[T]>
source§impl<'a, T: Copy + Send + Sync + Hash + Eq + 'static> PartialEq<ArcIntern<[T]>> for Box<[T]>
impl<'a, T: Copy + Send + Sync + Hash + Eq + 'static> PartialEq<ArcIntern<[T]>> for Box<[T]>
source§impl<'a, T: Copy + Send + Sync + Hash + Eq + 'static> PartialEq<ArcIntern<[T]>> for Cow<'a, [T]>
impl<'a, T: Copy + Send + Sync + Hash + Eq + 'static> PartialEq<ArcIntern<[T]>> for Cow<'a, [T]>
source§impl<'a, T: Copy + Send + Sync + Hash + Eq + 'static> PartialEq<ArcIntern<[T]>> for Rc<[T]>
impl<'a, T: Copy + Send + Sync + Hash + Eq + 'static> PartialEq<ArcIntern<[T]>> for Rc<[T]>
source§impl<'a, T: Copy + Send + Sync + Hash + Eq + 'static> PartialEq<ArcIntern<[T]>> for Vec<T>
impl<'a, T: Copy + Send + Sync + Hash + Eq + 'static> PartialEq<ArcIntern<[T]>> for Vec<T>
source§impl<'a> PartialEq<ArcIntern<str>> for &'a str
impl<'a> PartialEq<ArcIntern<str>> for &'a str
source§impl<'a> PartialEq<ArcIntern<str>> for Arc<str>
impl<'a> PartialEq<ArcIntern<str>> for Arc<str>
source§impl<'a> PartialEq<ArcIntern<str>> for Box<str>
impl<'a> PartialEq<ArcIntern<str>> for Box<str>
source§impl<'a> PartialEq<ArcIntern<str>> for Cow<'a, str>
impl<'a> PartialEq<ArcIntern<str>> for Cow<'a, str>
source§impl<'a> PartialEq<ArcIntern<str>> for Rc<str>
impl<'a> PartialEq<ArcIntern<str>> for Rc<str>
source§impl<'a> PartialEq<ArcIntern<str>> for String
impl<'a> PartialEq<ArcIntern<str>> for String
source§impl<'a> PartialEq<ArcIntern<str>> for str
impl<'a> PartialEq<ArcIntern<str>> for str
source§impl<'a, T: Copy + Send + Sync + Hash + Eq + 'static> PartialEq<Box<[T]>> for ArcIntern<[T]>
impl<'a, T: Copy + Send + Sync + Hash + Eq + 'static> PartialEq<Box<[T]>> for ArcIntern<[T]>
source§impl<'a> PartialEq<Box<str>> for ArcIntern<str>
impl<'a> PartialEq<Box<str>> for ArcIntern<str>
source§impl<'a, T: Copy + Send + Sync + Hash + Eq + 'static> PartialEq<Cow<'a, [T]>> for ArcIntern<[T]>
impl<'a, T: Copy + Send + Sync + Hash + Eq + 'static> PartialEq<Cow<'a, [T]>> for ArcIntern<[T]>
source§impl<'a> PartialEq<Cow<'a, str>> for ArcIntern<str>
impl<'a> PartialEq<Cow<'a, str>> for ArcIntern<str>
source§impl<T: ?Sized + Eq + Hash + Send + Sync> PartialEq for ArcIntern<T>
impl<T: ?Sized + Eq + Hash + Send + Sync> PartialEq for ArcIntern<T>
source§impl<T: ?Sized + Eq + Hash + Send + Sync + PartialOrd> PartialOrd for ArcIntern<T>
impl<T: ?Sized + Eq + Hash + Send + Sync + PartialOrd> PartialOrd for ArcIntern<T>
source§impl<T: ?Sized + Eq + Hash + Send + Sync + Serialize> Serialize for ArcIntern<T>
Available on crate feature serde
only.
impl<T: ?Sized + Eq + Hash + Send + Sync + Serialize> Serialize for ArcIntern<T>
serde
only.