pub struct Interner<S = Symbol, H = RandomState> { /* private fields */ }Expand description
String interner.
This is a thin wrapper around BytesInterner that uses str instead of [u8].
See the crate-level docs for more details.
Implementations§
Source§impl Interner<Symbol, RandomState>
impl Interner<Symbol, RandomState>
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates a new Interner with the given capacity and default symbol and hasher.
Source§impl<S: InternerSymbol, H: BuildHasher> Interner<S, H>
impl<S: InternerSymbol, H: BuildHasher> Interner<S, H>
Sourcepub fn with_hasher(hash_builder: H) -> Self
pub fn with_hasher(hash_builder: H) -> Self
Creates a new Interner with the given custom hasher.
Sourcepub fn with_capacity_and_hasher(capacity: usize, hash_builder: H) -> Self
pub fn with_capacity_and_hasher(capacity: usize, hash_builder: H) -> Self
Creates a new Interner with the given capacitiy and custom hasher.
Sourcepub fn iter(&self) -> impl ExactSizeIterator<Item = (S, &str)> + Clone
pub fn iter(&self) -> impl ExactSizeIterator<Item = (S, &str)> + Clone
Returns an iterator over the interned strings and their corresponding Symbols.
Does not guarantee that it includes symbols added after the iterator was created.
Sourcepub fn all_symbols(
&self,
) -> impl ExactSizeIterator<Item = S> + Send + Sync + Clone
pub fn all_symbols( &self, ) -> impl ExactSizeIterator<Item = S> + Send + Sync + Clone
Returns an iterator over all symbols in the interner.
Sourcepub fn intern(&self, s: &str) -> S
pub fn intern(&self, s: &str) -> S
Interns a string, returning its unique Symbol.
Allocates the string internally if it is not already interned.
If s outlives self, like &'static str, prefer using
intern_static, as it will not allocate the string on the heap.
Sourcepub fn intern_mut(&mut self, s: &str) -> S
pub fn intern_mut(&mut self, s: &str) -> S
Interns a string, returning its unique Symbol.
Allocates the string internally if it is not already interned.
If s outlives self, like &'static str, prefer using
intern_mut_static, as it will not allocate the string on the
heap.
By taking &mut self, this never acquires any locks.
Sourcepub fn intern_static<'a, 'b: 'a>(&'a self, s: &'b str) -> S
pub fn intern_static<'a, 'b: 'a>(&'a self, s: &'b str) -> S
Interns a static string, returning its unique Symbol.
Note that this only requires that s outlives self, which means we can avoid allocating
the string.
Sourcepub fn intern_mut_static<'a, 'b: 'a>(&'a mut self, s: &'b str) -> S
pub fn intern_mut_static<'a, 'b: 'a>(&'a mut self, s: &'b str) -> S
Interns a static string, returning its unique Symbol.
Note that this only requires that s outlives self, which means we can avoid allocating
the string.
By taking &mut self, this never acquires any locks.
Sourcepub fn intern_many<'a>(&self, strings: impl IntoIterator<Item = &'a str>)
pub fn intern_many<'a>(&self, strings: impl IntoIterator<Item = &'a str>)
Interns multiple strings.
Allocates the strings internally if they are not already interned.
If the strings outlive self, like &'static str, prefer using
intern_many_static, as it will not allocate the strings on the
heap.
Sourcepub fn intern_many_mut<'a>(
&mut self,
strings: impl IntoIterator<Item = &'a str>,
)
pub fn intern_many_mut<'a>( &mut self, strings: impl IntoIterator<Item = &'a str>, )
Interns multiple strings.
Allocates the strings internally if they are not already interned.
If the strings outlive self, like &'static str, prefer using
intern_many_mut_static, as it will not allocate the
strings on the heap.
By taking &mut self, this never acquires any locks.
Sourcepub fn intern_many_static<'a, 'b: 'a>(
&'a self,
strings: impl IntoIterator<Item = &'b str>,
)
pub fn intern_many_static<'a, 'b: 'a>( &'a self, strings: impl IntoIterator<Item = &'b str>, )
Interns multiple static strings.
Note that this only requires that the strings outlive self, which means we can avoid
allocating the strings.
Sourcepub fn intern_many_mut_static<'a, 'b: 'a>(
&'a mut self,
strings: impl IntoIterator<Item = &'b str>,
)
pub fn intern_many_mut_static<'a, 'b: 'a>( &'a mut self, strings: impl IntoIterator<Item = &'b str>, )
Interns multiple static strings.
Note that this only requires that the strings outlive self, which means we can avoid
allocating the strings.
By taking &mut self, this never acquires any locks.
Trait Implementations§
Auto Trait Implementations§
impl<S = Symbol, H = RandomState> !Freeze for Interner<S, H>
impl<S = Symbol, H = RandomState> !RefUnwindSafe for Interner<S, H>
impl<S, H> Send for Interner<S, H>
impl<S, H> Sync for Interner<S, H>
impl<S, H> Unpin for Interner<S, H>where
H: Unpin,
impl<S = Symbol, H = RandomState> !UnwindSafe for Interner<S, H>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more