[][src]Struct string_interner::StringInterner

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]

pub fn new() -> StringInterner<S, RandomState>[src]

Creates a new empty StringInterner.

pub fn with_capacity(cap: usize) -> Self[src]

Creates a new StringInterner with the given initial capacity.

pub fn capacity(&self) -> usize[src]

Returns the number of elements the StringInterner can hold without reallocating.

pub fn reserve(&mut self, additional: usize)[src]

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]

pub fn with_hasher(hash_builder: H) -> StringInterner<S, H>[src]

Creates a new empty StringInterner with the given hasher.

pub fn with_capacity_and_hasher(
    cap: usize,
    hash_builder: H
) -> StringInterner<S, H>
[src]

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]

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]

Returns the string slice associated with the given symbol if available, otherwise returns None.

pub unsafe fn resolve_unchecked(&self, symbol: S) -> &str[src]

Returns 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]

Returns the symbol associated with the given string for this interner if existent, otherwise returns None.

pub fn len(&self) -> usize[src]

Returns the number of uniquely interned strings within this interner.

pub fn is_empty(&self) -> bool[src]

Returns true if the string interner holds no elements.

Important traits for Iter<'a, S>
pub fn iter(&self) -> Iter<S>[src]

Returns an iterator over the interned strings.

Important traits for Values<'a, S>
pub fn iter_values(&self) -> Values<S>[src]

Returns an iterator over all intern indices and their associated strings.

pub fn shrink_to_fit(&mut self)[src]

Shrinks the capacity of the interner as much as possible.

Trait Implementations

impl<S, H> Send for StringInterner<S, H> where
    S: Symbol + Send,
    H: BuildHasher
[src]

impl<S, H> Sync for StringInterner<S, H> where
    S: Symbol + Sync,
    H: BuildHasher
[src]

impl<S, H> PartialEq<StringInterner<S, H>> for StringInterner<S, H> where
    S: Symbol,
    H: BuildHasher
[src]

#[must_use] fn ne(&self, other: &Rhs) -> bool1.0.0[src]

This method tests for !=.

impl Default for StringInterner<Sym, RandomState>[src]

impl<S, H> IntoIterator for StringInterner<S, H> where
    S: Symbol,
    H: BuildHasher
[src]

type Item = (S, String)

The type of the elements being iterated over.

type IntoIter = IntoIter<S>

Which kind of iterator are we turning this into?

impl<T, S> Extend<T> for StringInterner<S> where
    S: Symbol,
    T: Into<String> + AsRef<str>, 
[src]

impl<S, H> Clone for StringInterner<S, H> where
    S: Symbol,
    H: Clone + BuildHasher
[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

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: Debug, H: Debug> Debug for StringInterner<S, H> where
    S: Symbol,
    H: BuildHasher
[src]

impl<T, S> FromIterator<T> for StringInterner<S> where
    S: Symbol,
    T: Into<String> + AsRef<str>, 
[src]

impl<Sym, H> Serialize for StringInterner<Sym, H> where
    Sym: Symbol,
    H: BuildHasher
[src]

impl<'de, Sym, H> Deserialize<'de> for StringInterner<Sym, H> where
    Sym: Symbol,
    H: BuildHasher + Default
[src]

Auto Trait Implementations

impl<S, H> Unpin for StringInterner<S, H> where
    H: Unpin,
    S: Unpin

impl<S, H> UnwindSafe for StringInterner<S, H> where
    H: UnwindSafe,
    S: UnwindSafe

impl<S, H> RefUnwindSafe for StringInterner<S, H> where
    H: RefUnwindSafe,
    S: RefUnwindSafe

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: Deserialize<'de>, 
[src]