[−][src]Struct string_interner::StringInterner
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,
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]
Sym: Symbol,
H: BuildHasher,
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]
cap: usize,
hash_builder: H
) -> StringInterner<Sym, 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) -> Sym where
T: Into<String> + AsRef<str>,
[src]
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: 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]
T: AsRef<str>,
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]
Sym: Symbol + Send,
H: BuildHasher,
impl<Sym, H> Clone for StringInterner<Sym, H> where
Sym: Symbol,
H: Clone + BuildHasher,
[src]
Sym: Symbol,
H: Clone + BuildHasher,
fn clone(&self) -> Self
[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]
Sym: Symbol,
H: BuildHasher,
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?
fn into_iter(self) -> Self::IntoIter
[src]
impl<Sym: Eq, H: Eq> Eq for StringInterner<Sym, H> where
Sym: Symbol,
H: BuildHasher,
[src]
Sym: Symbol,
H: BuildHasher,
impl<Sym, H> PartialEq<StringInterner<Sym, H>> for StringInterner<Sym, H> where
Sym: Symbol,
H: BuildHasher,
[src]
Sym: Symbol,
H: BuildHasher,
fn eq(&self, rhs: &Self) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl<Sym, H> Sync for StringInterner<Sym, H> where
Sym: Symbol + Sync,
H: BuildHasher,
[src]
Sym: Symbol + Sync,
H: BuildHasher,
impl<Sym: Debug, H: Debug> Debug for StringInterner<Sym, H> where
Sym: Symbol,
H: BuildHasher,
[src]
Sym: Symbol,
H: BuildHasher,
impl<Sym, H> Serialize for StringInterner<Sym, H> where
Sym: Symbol,
H: BuildHasher,
[src]
Sym: Symbol,
H: BuildHasher,
impl<'de, Sym, H> Deserialize<'de> for StringInterner<Sym, H> where
Sym: Symbol,
H: BuildHasher + Default,
[src]
Sym: Symbol,
H: BuildHasher + Default,
fn deserialize<D>(deserializer: D) -> Result<StringInterner<Sym, H>, D::Error> where
D: Deserializer<'de>,
[src]
D: Deserializer<'de>,
Auto Trait Implementations
impl<Sym, H> Unpin for StringInterner<Sym, H> where
H: Unpin,
Sym: Unpin,
H: Unpin,
Sym: Unpin,
impl<Sym, H> UnwindSafe for StringInterner<Sym, H> where
H: UnwindSafe,
Sym: UnwindSafe,
H: UnwindSafe,
Sym: UnwindSafe,
impl<Sym, H> RefUnwindSafe for StringInterner<Sym, H> where
H: RefUnwindSafe,
Sym: RefUnwindSafe,
H: RefUnwindSafe,
Sym: RefUnwindSafe,
Blanket Implementations
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<I> IntoIterator for I where
I: Iterator,
[src]
I: Iterator,
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?
fn into_iter(self) -> I
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> DeserializeOwned for T where
T: Deserialize<'de>,
[src]
T: Deserialize<'de>,