Struct internment::ArcIntern
source · [−]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("world");
assert_eq!(x, ArcIntern::from("hello"));
assert_eq!(&*x, "hello"); // dereference an ArcIntern like a pointer
Implementations
sourceimpl<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.
sourcepub fn from<'a, Q: ?Sized + Eq + Hash + 'a>(val: &'a Q) -> ArcIntern<T> where
T: Borrow<Q> + From<&'a Q>,
pub fn from<'a, Q: ?Sized + Eq + Hash + 'a>(val: &'a Q) -> ArcIntern<T> where
T: Borrow<Q> + From<&'a Q>,
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.
Trait Implementations
sourceimpl<T: Eq + Hash + Send + Sync> Hash for ArcIntern<T>
impl<T: 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.
sourceimpl<T: Eq + Hash + Send + Sync + Ord> Ord for ArcIntern<T>
impl<T: Eq + Hash + Send + Sync + Ord> Ord for ArcIntern<T>
sourceimpl<T: Eq + Hash + Send + Sync + PartialOrd> PartialOrd<ArcIntern<T>> for ArcIntern<T>
impl<T: Eq + Hash + Send + Sync + PartialOrd> PartialOrd<ArcIntern<T>> for ArcIntern<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: Eq + Hash + Send + Sync> Eq for ArcIntern<T>
impl<T: Eq + Hash + Send + Sync> Send for ArcIntern<T>
impl<T: Eq + Hash + Send + Sync> Sync for ArcIntern<T>
Auto Trait Implementations
impl<T> RefUnwindSafe for ArcIntern<T> where
T: RefUnwindSafe,
impl<T> Unpin for ArcIntern<T>
impl<T> UnwindSafe for ArcIntern<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