Struct mentat_core::intern_set::InternSet
[−]
[src]
An InternSet
allows to "intern" some potentially large values, maintaining a single value
instance owned by the InternSet
and leaving consumers with lightweight ref-counted handles to
the large owned value. This can avoid expensive clone() operations.
In Mentat, such large values might be strings or arbitrary [a v] pairs.
See https://en.wikipedia.org/wiki/String_interning for discussion.
Fields
inner: HashSet<Rc<T>>
Methods
impl<T> InternSet<T> where
T: Eq + Hash,
[src]
impl<T> InternSet<T> where
T: Eq + Hash,
pub fn new() -> InternSet<T>
[src]
pub fn new() -> InternSet<T>
pub fn len(&self) -> usize
[src]
pub fn len(&self) -> usize
pub fn intern<R: Into<Rc<T>>>(&mut self, value: R) -> Rc<T>
[src]
pub fn intern<R: Into<Rc<T>>>(&mut self, value: R) -> Rc<T>
Intern a value, providing a ref-counted handle to the interned value.
use std::rc::Rc; use mentat_core::intern_set::InternSet; let mut s = InternSet::new(); let one = "foo".to_string(); let two = Rc::new("foo".to_string()); let out_one = s.intern(one); assert_eq!(out_one, two); // assert!(!&out_one.ptr_eq(&two)); // Nightly-only. let out_two = s.intern(two); assert_eq!(out_one, out_two); assert_eq!(1, s.inner.len()); // assert!(&out_one.ptr_eq(&out_two)); // Nightly-only.
Trait Implementations
impl<T: Clone> Clone for InternSet<T> where
T: Eq + Hash,
[src]
impl<T: Clone> Clone for InternSet<T> where
T: Eq + Hash,
fn clone(&self) -> InternSet<T>
[src]
fn clone(&self) -> InternSet<T>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
1.0.0
[src]Performs copy-assignment from source
. Read more
impl<T: Debug> Debug for InternSet<T> where
T: Eq + Hash,
[src]
impl<T: Debug> Debug for InternSet<T> where
T: Eq + Hash,
fn fmt(&self, __arg_0: &mut Formatter) -> Result
[src]
fn fmt(&self, __arg_0: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl<T: Default> Default for InternSet<T> where
T: Eq + Hash,
[src]
impl<T: Default> Default for InternSet<T> where
T: Eq + Hash,
impl<T: Eq> Eq for InternSet<T> where
T: Eq + Hash,
[src]
impl<T: Eq> Eq for InternSet<T> where
T: Eq + Hash,
impl<T: PartialEq> PartialEq for InternSet<T> where
T: Eq + Hash,
[src]
impl<T: PartialEq> PartialEq for InternSet<T> where
T: Eq + Hash,