Struct string_interner::StringInterner
[−]
[src]
pub struct StringInterner<Sym> where
Sym: Symbol, { /* fields omitted */ }
Provides a bidirectional mapping between String stored within the interner and indices. The main purpose is to store every unique String only once and make it possible to reference it via lightweight indices.
Compilers often use this for implementing a symbol table.
The main goal of this StringInterner
is to store String
with as low memory overhead as possible.
Methods
impl<Sym> StringInterner<Sym> where
Sym: Symbol,
[src]
Sym: Symbol,
fn new() -> Self
Creates a new empty StringInterner
.
Used instead of Deriving from Default to not make internals depend on it.
fn with_capacity(cap: usize) -> Self
Creates a new StringInterner
with a given capacity.
fn get_or_intern<T>(&mut self, val: T) -> Sym where
T: Into<String> + AsRef<str>,
T: Into<String> + AsRef<str>,
Interns the given value.
Returns a symbol to access it within this interner.
This either copies the contents of the string (e.g. for str) or moves them into this interner (e.g. for String).
fn resolve(&self, symbol: Sym) -> Option<&str>
Returns a string slice to the string identified by the given symbol if available. Else, None is returned.
unsafe fn resolve_unchecked(&self, symbol: Sym) -> &str
Returns a string slice to the string identified by the given symbol, without doing bounds checking. So use it very carefully!
fn get<T>(&self, val: T) -> Option<Sym> where
T: AsRef<str>,
T: AsRef<str>,
Returns the given string's symbol for this interner if existent.
fn len(&self) -> usize
Returns the number of uniquely stored Strings interned within this interner.
fn is_empty(&self) -> bool
Returns true if the string interner internes no elements.
fn iter(&self) -> Iter<Sym>
Returns an iterator over the interned strings.
fn iter_values(&self) -> Values<Sym>
Returns an iterator over all intern indices and their associated strings.
fn clear(&mut self)
Removes all interned Strings from this interner.
This invalides all Symbol
entities instantiated by it so far.
Trait Implementations
impl<Sym> Send for StringInterner<Sym> where
Sym: Symbol + Send,
[src]
Sym: Symbol + Send,
impl<Sym> Sync for StringInterner<Sym> where
Sym: Symbol + Sync,
[src]
Sym: Symbol + Sync,
impl<Sym: Debug> Debug for StringInterner<Sym> where
Sym: Symbol,
[src]
Sym: Symbol,
impl<Sym: Clone> Clone for StringInterner<Sym> where
Sym: Symbol,
[src]
Sym: Symbol,
fn clone(&self) -> StringInterner<Sym>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl<Sym: PartialEq> PartialEq for StringInterner<Sym> where
Sym: Symbol,
[src]
Sym: Symbol,
fn eq(&self, __arg_0: &StringInterner<Sym>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &StringInterner<Sym>) -> bool
This method tests for !=
.
impl<Sym: Eq> Eq for StringInterner<Sym> where
Sym: Symbol,
[src]
Sym: Symbol,
impl<S> Default for StringInterner<S> where
S: Symbol,
[src]
S: Symbol,
impl<Sym> IntoIterator for StringInterner<Sym> where
Sym: Symbol,
[src]
Sym: Symbol,