pub struct BytesInterner<S = Symbol, H = RandomState> { /* private fields */ }
Expand description
Byte string interner.
See the crate-level docs for more details.
Implementations§
Source§impl BytesInterner<Symbol, RandomState>
impl BytesInterner<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> BytesInterner<S, H>
impl<S: InternerSymbol, H: BuildHasher> BytesInterner<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, &[u8])> + Clone
pub fn iter(&self) -> impl ExactSizeIterator<Item = (S, &[u8])> + Clone
Returns an iterator over the interned strings and their corresponding Symbol
s.
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: &[u8]) -> S
pub fn intern(&self, s: &[u8]) -> S
Interns a string, returning its unique Symbol
.
Allocates the string internally if it is not already interned.
If s
outlives self
, like &'static [u8]
, prefer using
intern_static
, as it will not allocate the string on the heap.
Sourcepub fn intern_mut(&mut self, s: &[u8]) -> S
pub fn intern_mut(&mut self, s: &[u8]) -> S
Interns a string, returning its unique Symbol
.
Allocates the string internally if it is not already interned.
If s
outlives self
, like &'static [u8]
, 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 [u8]) -> S
pub fn intern_static<'a, 'b: 'a>(&'a self, s: &'b [u8]) -> 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 [u8]) -> S
pub fn intern_mut_static<'a, 'b: 'a>(&'a mut self, s: &'b [u8]) -> 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 [u8]>)
pub fn intern_many<'a>(&self, strings: impl IntoIterator<Item = &'a [u8]>)
Interns multiple strings.
Allocates the strings internally if they are not already interned.
If the strings outlive self
, like &'static [u8]
, 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 [u8]>,
)
pub fn intern_many_mut<'a>( &mut self, strings: impl IntoIterator<Item = &'a [u8]>, )
Interns multiple strings.
Allocates the strings internally if they are not already interned.
If the strings outlive self
, like &'static [u8]
, 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 [u8]>,
)
pub fn intern_many_static<'a, 'b: 'a>( &'a self, strings: impl IntoIterator<Item = &'b [u8]>, )
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 [u8]>,
)
pub fn intern_many_mut_static<'a, 'b: 'a>( &'a mut self, strings: impl IntoIterator<Item = &'b [u8]>, )
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.