Struct Interner

Source
pub struct Interner<H = DefaultHashBuilder>
where H: BuildHasher,
{ /* private fields */ }
Expand description

Data structure that allows to resolve/intern strings.

See:

Implementations§

Source§

impl<H> Interner<H>
where H: BuildHasher + Default,

Source

pub fn new() -> Self

Creates a new empty Interner.

Source

pub fn with_hasher(hasher: H) -> Self

Creates a new empty Interner with the given hasher.

Source

pub fn with_capacity(capacity: usize) -> Self

Creates a new empty Interner with the given capacity.

Source

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

Creates a new empty Interner with the given capacity and hasher.

Source

pub fn len(&self) -> usize

Returns the number of symbols/strings interned by the interner.

Source

pub fn is_empty(&self) -> bool

Returns true if the string interner has no interned strings/amount of symbols is 0.

Source

pub fn get<T>(&self, string: T) -> Option<usize>
where T: AsRef<str>,

Returns the symbol for the given string if any.

Source

pub fn get_or_intern<T>(&mut self, string: T) -> usize
where T: AsRef<str>,

Interns the given string and returns a corresponding symbol.

Source

pub fn get_or_intern_static(&mut self, string: &'static str) -> usize

Interns the given 'static string and returns a corresponding symbol.

Source

pub fn shrink_to_fit(&mut self)

Shrink backend capacity to fit the interned strings exactly.

Source

pub fn resolve(&self, symbol: usize) -> Option<&str>

Returns the string for the given symbol if any.

Trait Implementations§

Source§

impl<H> Debug for Interner<H>
where H: BuildHasher + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Interner

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<H> Freeze for Interner<H>
where H: Freeze,

§

impl<H> RefUnwindSafe for Interner<H>
where H: RefUnwindSafe,

§

impl<H> Send for Interner<H>
where H: Send,

§

impl<H> Sync for Interner<H>
where H: Sync,

§

impl<H> Unpin for Interner<H>
where H: Unpin,

§

impl<H> UnwindSafe for Interner<H>
where H: UnwindSafe,

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.