Struct BytesInterner

Source
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>

Source

pub fn new() -> Self

Creates a new, empty Interner with the default symbol and hasher.

Source

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>

Source

pub fn with_hasher(hash_builder: H) -> Self

Creates a new Interner with the given custom hasher.

Source

pub fn with_capacity_and_hasher(capacity: usize, hash_builder: H) -> Self

Creates a new Interner with the given capacitiy and custom hasher.

Source

pub fn len(&self) -> usize

Returns the number of unique strings in the interner.

Source

pub fn is_empty(&self) -> bool

Returns true if the interner is empty.

Source

pub fn iter(&self) -> impl ExactSizeIterator<Item = (S, &[u8])> + 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.

Source

pub fn all_symbols( &self, ) -> impl ExactSizeIterator<Item = S> + Send + Sync + Clone

Returns an iterator over all symbols in the interner.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn resolve(&self, sym: S) -> &[u8]

Maps a Symbol to its string. This is a cheap, lock-free operation.

§Panics

Panics if Symbol is out of bounds of this Interner. You should only use Symbols created by this Interner.

Trait Implementations§

Source§

impl Default for BytesInterner

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<S = Symbol, H = RandomState> !Freeze for BytesInterner<S, H>

§

impl<S = Symbol, H = RandomState> !RefUnwindSafe for BytesInterner<S, H>

§

impl<S, H> Send for BytesInterner<S, H>
where H: Send, S: Send,

§

impl<S, H> Sync for BytesInterner<S, H>
where H: Sync, S: Send + Sync,

§

impl<S, H> Unpin for BytesInterner<S, H>
where H: Unpin,

§

impl<S = Symbol, H = RandomState> !UnwindSafe for BytesInterner<S, H>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.