[−][src]Struct string_interner::StringInterner
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]
S: Symbol,
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]
S: Symbol,
H: BuildHasher,
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]
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]
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]
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]
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]
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]
S: Symbol + Send,
H: BuildHasher,
impl<S, H> Sync for StringInterner<S, H> where
S: Symbol + Sync,
H: BuildHasher,
[src]
S: Symbol + Sync,
H: BuildHasher,
impl<S, H> PartialEq<StringInterner<S, H>> for StringInterner<S, H> where
S: Symbol,
H: BuildHasher,
[src]
S: 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 Default for StringInterner<Sym, RandomState>
[src]
impl<S, H> IntoIterator for StringInterner<S, H> where
S: Symbol,
H: BuildHasher,
[src]
S: Symbol,
H: BuildHasher,
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?
fn into_iter(self) -> Self::IntoIter
[src]
impl<T, S> Extend<T> for StringInterner<S> where
S: Symbol,
T: Into<String> + AsRef<str>,
[src]
S: Symbol,
T: Into<String> + AsRef<str>,
fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = T>,
[src]
I: IntoIterator<Item = T>,
impl<S, H> Clone for StringInterner<S, H> where
S: Symbol,
H: Clone + BuildHasher,
[src]
S: 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<S: Eq, H: Eq> Eq for StringInterner<S, H> where
S: Symbol,
H: BuildHasher,
[src]
S: Symbol,
H: BuildHasher,
impl<S: Debug, H: Debug> Debug for StringInterner<S, H> where
S: Symbol,
H: BuildHasher,
[src]
S: Symbol,
H: BuildHasher,
impl<T, S> FromIterator<T> for StringInterner<S> where
S: Symbol,
T: Into<String> + AsRef<str>,
[src]
S: Symbol,
T: Into<String> + AsRef<str>,
fn from_iter<I>(iter: I) -> Self where
I: IntoIterator<Item = T>,
[src]
I: IntoIterator<Item = T>,
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<S, H> Unpin for StringInterner<S, H> where
H: Unpin,
S: Unpin,
H: Unpin,
S: Unpin,
impl<S, H> UnwindSafe for StringInterner<S, H> where
H: UnwindSafe,
S: UnwindSafe,
H: UnwindSafe,
S: UnwindSafe,
impl<S, H> RefUnwindSafe for StringInterner<S, H> where
H: RefUnwindSafe,
S: RefUnwindSafe,
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]
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> 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, 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>,