[][src]Struct string_interner::StringInterner

pub struct StringInterner<Sym, H = RandomState> where
    Sym: Symbol,
    H: BuildHasher
{ /* 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]

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

Creates a new empty StringInterner.

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

Creates a new StringInterner with the given initial capacity.

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

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

Creates a new empty StringInterner with the given hasher.

pub fn with_capacity_and_hasher(
    cap: usize,
    hash_builder: H
) -> StringInterner<Sym, 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) -> Sym 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: Sym) -> Option<&str>[src]

Returns a string slice to the string identified by the given symbol if available. Else, None is returned.

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

Returns a string slice to the string identified by the given symbol, without doing bounds checking. So use it very carefully!

pub fn get<T>(&self, val: T) -> Option<Sym> where
    T: AsRef<str>, 
[src]

Returns the given string's symbol for this interner if existent.

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

Returns the number of uniquely stored Strings interned within this interner.

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

Returns true if the string interner internes no elements.

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

Returns an iterator over the interned strings.

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

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

pub fn clear(&mut self)[src]

Removes all interned Strings from this interner.

This invalides all Symbol entities instantiated by it so far.

pub fn shrink_to_fit(&mut self)[src]

Shrinks the capacity of the interner as much as possible.

Trait Implementations

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

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

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

Performs copy-assignment from source. Read more

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

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

type Item = (Sym, String)

The type of the elements being iterated over.

type IntoIter = IntoIter<Sym>

Which kind of iterator are we turning this into?

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

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

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

This method tests for !=.

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

impl<Sym: Debug, H: Debug> Debug for StringInterner<Sym, H> where
    Sym: Symbol,
    H: BuildHasher
[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<Sym, H> Unpin for StringInterner<Sym, H> where
    H: Unpin,
    Sym: Unpin

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

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

Blanket Implementations

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

type Owned = T

The resulting type after obtaining ownership.

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