[−][src]Struct string_interner::StringInterner
Data structure to intern and resolve strings.
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.
The following API covers the main functionality:
StringInterner::get_or_intern
: To intern a new string.- This maps from
string
type tosymbol
type.
- This maps from
StringInterner::resolve
: To resolve your already interned strings.- This maps from
symbol
type tostring
type.
- This maps from
Implementations
impl<S, B, H> StringInterner<S, B, H> where
S: Symbol,
B: Backend<S>,
H: BuildHasher + Default,
[src]
S: Symbol,
B: Backend<S>,
H: BuildHasher + Default,
pub fn new() -> Self
[src]
Creates a new empty StringInterner
.
pub fn with_capacity(cap: usize) -> Self
[src]
Creates a new StringInterner
with the given initial capacity.
impl<S, B, H> StringInterner<S, B, H> where
S: Symbol,
B: Backend<S>,
H: BuildHasher,
[src]
S: Symbol,
B: Backend<S>,
H: BuildHasher,
pub fn with_hasher(hash_builder: H) -> Self
[src]
Creates a new empty StringInterner
with the given hasher.
pub fn with_capacity_and_hasher(cap: usize, hash_builder: H) -> Self
[src]
Creates a new empty StringInterner
with the given initial capacity and the given hasher.
pub fn len(&self) -> usize
[src]
Returns the number of strings interned by the interner.
pub fn is_empty(&self) -> bool
[src]
Returns true
if the string interner has no interned strings.
pub fn get<T>(&self, string: T) -> Option<S> where
T: AsRef<str>,
[src]
T: AsRef<str>,
Returns the symbol for the given string if any.
Can be used to query if a string has already been interned without interning.
pub fn get_or_intern<T>(&mut self, string: T) -> S where
T: AsRef<str>,
[src]
T: AsRef<str>,
Interns the given string.
Returns a symbol for resolution into the original string.
Panics
If the interner already interns the maximum number of strings possible by the chosen symbol type.
pub fn get_or_intern_static(&mut self, string: &'static str) -> S
[src]
Interns the given 'static
string.
Returns a symbol for resolution into the original string.
Note
This is more efficient than StringInterner::get_or_intern
since it might
avoid some memory allocations if the backends supports this.
Panics
If the interner already interns the maximum number of strings possible by the chosen symbol type.
pub fn resolve(&self, symbol: S) -> Option<&str>
[src]
Returns the string for the given symbol if any.
Trait Implementations
impl<S, B, H> Clone for StringInterner<S, B, H> where
S: Symbol,
B: Backend<S> + Clone,
H: BuildHasher + Clone,
[src]
S: Symbol,
B: Backend<S> + Clone,
H: BuildHasher + Clone,
pub fn clone(&self) -> Self
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<S, B, H> Debug for StringInterner<S, B, H> where
S: Symbol + Debug,
B: Backend<S> + Debug,
H: BuildHasher,
[src]
S: Symbol + Debug,
B: Backend<S> + Debug,
H: BuildHasher,
impl Default for StringInterner
[src]
impl<'de, S, B, H> Deserialize<'de> for StringInterner<S, B, H> where
S: Symbol,
B: Backend<S>,
H: BuildHasher + Default,
[src]
S: Symbol,
B: Backend<S>,
H: BuildHasher + Default,
pub fn deserialize<D>(
deserializer: D
) -> Result<StringInterner<S, B, H>, D::Error> where
D: Deserializer<'de>,
[src]
deserializer: D
) -> Result<StringInterner<S, B, H>, D::Error> where
D: Deserializer<'de>,
impl<S, B, H> Eq for StringInterner<S, B, H> where
S: Symbol,
B: Backend<S> + Eq,
H: BuildHasher,
[src]
S: Symbol,
B: Backend<S> + Eq,
H: BuildHasher,
impl<S, B, H, T> Extend<T> for StringInterner<S, B, H> where
S: Symbol,
B: Backend<S>,
H: BuildHasher,
T: AsRef<str>,
[src]
S: Symbol,
B: Backend<S>,
H: BuildHasher,
T: AsRef<str>,
pub fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = T>,
[src]
I: IntoIterator<Item = T>,
pub fn extend_one(&mut self, item: A)
[src]
pub fn extend_reserve(&mut self, additional: usize)
[src]
impl<S, B, H, T> FromIterator<T> for StringInterner<S, B, H> where
S: Symbol,
B: Backend<S>,
H: BuildHasher + Default,
T: AsRef<str>,
[src]
S: Symbol,
B: Backend<S>,
H: BuildHasher + Default,
T: AsRef<str>,
pub fn from_iter<I>(iter: I) -> Self where
I: IntoIterator<Item = T>,
[src]
I: IntoIterator<Item = T>,
impl<'a, S, B, H> IntoIterator for &'a StringInterner<S, B, H> where
S: Symbol,
B: Backend<S>,
&'a B: IntoIterator<Item = (S, &'a str)>,
H: BuildHasher,
[src]
S: Symbol,
B: Backend<S>,
&'a B: IntoIterator<Item = (S, &'a str)>,
H: BuildHasher,
type Item = (S, &'a str)
The type of the elements being iterated over.
type IntoIter = <&'a B as IntoIterator>::IntoIter
Which kind of iterator are we turning this into?
pub fn into_iter(self) -> Self::IntoIter
[src]
impl<S, B, H> PartialEq<StringInterner<S, B, H>> for StringInterner<S, B, H> where
S: Symbol,
B: Backend<S> + PartialEq,
H: BuildHasher,
[src]
S: Symbol,
B: Backend<S> + PartialEq,
H: BuildHasher,
impl<S, B, H> Serialize for StringInterner<S, B, H> where
S: Symbol,
B: Backend<S>,
&'a B: IntoIterator<Item = (S, &'a str)>,
H: BuildHasher,
[src]
S: Symbol,
B: Backend<S>,
&'a B: IntoIterator<Item = (S, &'a str)>,
H: BuildHasher,
Auto Trait Implementations
impl<S, B, H> RefUnwindSafe for StringInterner<S, B, H> where
B: RefUnwindSafe,
H: RefUnwindSafe,
S: RefUnwindSafe,
[src]
B: RefUnwindSafe,
H: RefUnwindSafe,
S: RefUnwindSafe,
impl<S, B, H> Send for StringInterner<S, B, H> where
B: Send,
H: Send,
S: Send,
[src]
B: Send,
H: Send,
S: Send,
impl<S, B, H> Sync for StringInterner<S, B, H> where
B: Sync,
H: Sync,
S: Sync,
[src]
B: Sync,
H: Sync,
S: Sync,
impl<S, B, H> Unpin for StringInterner<S, B, H> where
B: Unpin,
H: Unpin,
S: Unpin,
[src]
B: Unpin,
H: Unpin,
S: Unpin,
impl<S, B, H> UnwindSafe for StringInterner<S, B, H> where
B: UnwindSafe,
H: UnwindSafe,
S: UnwindSafe,
[src]
B: UnwindSafe,
H: UnwindSafe,
S: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub 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.
pub 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>,