Struct string_interner::StringInterner [−][src]
pub struct StringInterner<S, H = RandomState> where
S: Symbol,
H: BuildHasher, { /* fields omitted */ }
Caches strings efficiently, with minimal memory footprint and associates them with unique symbols. These symbols allow constant time comparisons and look-ups to the underlying interned strings.
Methods
impl<S> StringInterner<S> where
S: Symbol, [src]
impl<S> StringInterner<S> where
S: Symbol, pub fn new() -> StringInterner<S, RandomState>[src]
pub fn new() -> StringInterner<S, RandomState>Creates a new empty StringInterner.
pub fn with_capacity(cap: usize) -> Self[src]
pub fn with_capacity(cap: usize) -> SelfCreates a new StringInterner with the given initial capacity.
pub fn capacity(&self) -> usize[src]
pub fn capacity(&self) -> usizeReturns the number of elements the StringInterner can hold without reallocating.
pub fn reserve(&mut self, additional: usize)[src]
pub fn reserve(&mut self, additional: usize)Reserves capacity for at least additional more elements to be interned into self.
The collection may reserve more space to avoid frequent allocations.
After calling reserve, capacity will be greater than or equal to self.len() + additional.
Does nothing if capacity is already sufficient.
impl<S, H> StringInterner<S, H> where
S: Symbol,
H: BuildHasher, [src]
impl<S, H> StringInterner<S, H> where
S: Symbol,
H: BuildHasher, pub fn with_hasher(hash_builder: H) -> StringInterner<S, H>[src]
pub fn with_hasher(hash_builder: H) -> StringInterner<S, H>Creates a new empty StringInterner with the given hasher.
pub fn with_capacity_and_hasher(
cap: usize,
hash_builder: H
) -> StringInterner<S, H>[src]
pub fn with_capacity_and_hasher(
cap: usize,
hash_builder: H
) -> StringInterner<S, H>Creates a new empty StringInterner with the given initial capacity and the given hasher.
pub fn get_or_intern<T>(&mut self, val: T) -> S where
T: Into<String> + AsRef<str>, [src]
pub fn get_or_intern<T>(&mut self, val: T) -> S where
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).
pub fn resolve(&self, symbol: S) -> Option<&str>[src]
pub fn resolve(&self, symbol: S) -> Option<&str>Returns the string slice associated with the given symbol if available,
otherwise returns None.
pub unsafe fn resolve_unchecked(&self, symbol: S) -> &str[src]
pub unsafe fn resolve_unchecked(&self, symbol: S) -> &strReturns the string associated with the given symbol.
Note
This does not check whether the given symbol has an associated string for the given string interner instance.
Safety
This will result in undefined behaviour if the given symbol had no associated string for this interner instance.
pub fn get<T>(&self, val: T) -> Option<S> where
T: AsRef<str>, [src]
pub fn get<T>(&self, val: T) -> Option<S> where
T: AsRef<str>, Returns the symbol associated with the given string for this interner
if existent, otherwise returns None.
pub fn len(&self) -> usize[src]
pub fn len(&self) -> usizeReturns the number of uniquely interned strings within this interner.
pub fn is_empty(&self) -> bool[src]
pub fn is_empty(&self) -> boolReturns true if the string interner holds no elements.
ⓘImportant traits for Iter<'a, S>pub fn iter(&self) -> Iter<S>[src]
pub fn iter(&self) -> Iter<S>Returns an iterator over the interned strings.
ⓘImportant traits for Values<'a, S>pub fn iter_values(&self) -> Values<S>[src]
pub fn iter_values(&self) -> Values<S>Returns an iterator over all intern indices and their associated strings.
pub fn shrink_to_fit(&mut self)[src]
pub fn shrink_to_fit(&mut self)Shrinks the capacity of the interner as much as possible.
Trait Implementations
impl<Sym, H> Serialize for StringInterner<Sym, H> where
Sym: Symbol,
H: BuildHasher, [src]
impl<Sym, H> Serialize for StringInterner<Sym, H> where
Sym: Symbol,
H: BuildHasher, fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where
S: Serializer, [src]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where
S: Serializer, Serialize this value into the given Serde serializer. Read more
impl<'de, Sym, H> Deserialize<'de> for StringInterner<Sym, H> where
Sym: Symbol,
H: BuildHasher + Default, [src]
impl<'de, Sym, H> Deserialize<'de> for StringInterner<Sym, H> where
Sym: Symbol,
H: BuildHasher + Default, fn deserialize<D>(deserializer: D) -> Result<StringInterner<Sym, H>, D::Error> where
D: Deserializer<'de>, [src]
fn deserialize<D>(deserializer: D) -> Result<StringInterner<Sym, H>, D::Error> where
D: Deserializer<'de>, Deserialize this value from the given Serde deserializer. Read more
impl<S: Debug, H: Debug> Debug for StringInterner<S, H> where
S: Symbol,
H: BuildHasher, [src]
impl<S: Debug, H: Debug> Debug for StringInterner<S, H> where
S: Symbol,
H: BuildHasher, fn fmt(&self, f: &mut Formatter) -> Result[src]
fn fmt(&self, f: &mut Formatter) -> ResultFormats the value using the given formatter. Read more
impl<S: Clone, H: Clone> Clone for StringInterner<S, H> where
S: Symbol,
H: BuildHasher, [src]
impl<S: Clone, H: Clone> Clone for StringInterner<S, H> where
S: Symbol,
H: BuildHasher, fn clone(&self) -> StringInterner<S, H>[src]
fn clone(&self) -> StringInterner<S, H>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)Performs copy-assignment from source. Read more
impl<S: Eq, H: Eq> Eq for StringInterner<S, H> where
S: Symbol,
H: BuildHasher, [src]
impl<S: Eq, H: Eq> Eq for StringInterner<S, H> where
S: Symbol,
H: BuildHasher, impl<S, H> PartialEq for StringInterner<S, H> where
S: Symbol,
H: BuildHasher, [src]
impl<S, H> PartialEq for StringInterner<S, H> where
S: Symbol,
H: BuildHasher, fn eq(&self, rhs: &Self) -> bool[src]
fn eq(&self, rhs: &Self) -> boolThis method tests for self and other values to be equal, and is used by ==. Read more
fn ne(&self, other: &Rhs) -> bool1.0.0[src]
fn ne(&self, other: &Rhs) -> boolThis method tests for !=.
impl Default for StringInterner<Sym, RandomState>[src]
impl Default for StringInterner<Sym, RandomState>impl<S, H> Send for StringInterner<S, H> where
S: Symbol + Send,
H: BuildHasher, [src]
impl<S, H> Send for StringInterner<S, H> where
S: Symbol + Send,
H: BuildHasher, impl<S, H> Sync for StringInterner<S, H> where
S: Symbol + Sync,
H: BuildHasher, [src]
impl<S, H> Sync for StringInterner<S, H> where
S: Symbol + Sync,
H: BuildHasher, impl<T, S> FromIterator<T> for StringInterner<S> where
S: Symbol,
T: Into<String> + AsRef<str>, [src]
impl<T, S> FromIterator<T> for StringInterner<S> where
S: Symbol,
T: Into<String> + AsRef<str>, fn from_iter<I>(iter: I) -> Self where
I: IntoIterator<Item = T>, [src]
fn from_iter<I>(iter: I) -> Self where
I: IntoIterator<Item = T>, Creates a value from an iterator. Read more
impl<S, H> IntoIterator for StringInterner<S, H> where
S: Symbol,
H: BuildHasher, [src]
impl<S, H> IntoIterator for StringInterner<S, H> where
S: Symbol,
H: BuildHasher,