Struct mentat_core::intern_set::InternSet [] [src]

pub struct InternSet<T> where
    T: Eq + Hash
{ pub inner: HashSet<Rc<T>>, }

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

Methods

impl<T> InternSet<T> where
    T: Eq + Hash
[src]

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]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<T: Debug> Debug for InternSet<T> where
    T: Eq + Hash
[src]

Formats the value using the given formatter. Read more

impl<T: Default> Default for InternSet<T> where
    T: Eq + Hash
[src]

Returns the "default value" for a type. Read more

impl<T: Eq> Eq for InternSet<T> where
    T: Eq + Hash
[src]

impl<T: PartialEq> PartialEq for InternSet<T> where
    T: Eq + Hash
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

impl<T> !Send for InternSet<T>

impl<T> !Sync for InternSet<T>