Skip to main content

Interner

Struct Interner 

Source
pub struct Interner { /* private fields */ }
Expand description

The owner of every Symbol.

The interner is an explicit handle rather than a thread-local or a process global. Two consequences are worth the extra parameter: a Symbol is meaningful only against the interner that made it, which is a fact the type system can be made to carry, and nothing in this workspace acquires hidden shared state to resolve a name.

Implementations§

Source§

impl Interner

Source

pub fn new() -> Self

Returns an interner that holds nothing.

Source

pub fn intern(&mut self, text: &str) -> Symbol

Returns the symbol for text, interning it if it is new.

§Panics

Panics when the interner already holds u32::MAX + 1 distinct identifiers, more than any source map can hold.

Source

pub fn resolve(&self, symbol: Symbol) -> &str

Returns the text symbol names.

§Panics

Panics when symbol came from a different interner, which is a defect rather than a condition to recover from.

Source

pub fn get(&self, text: &str) -> Option<Symbol>

Returns the symbol for text if it has already been interned.

Source

pub fn len(&self) -> usize

Returns how many distinct identifiers have been interned.

Source

pub fn is_empty(&self) -> bool

Returns whether nothing has been interned.

Trait Implementations§

Source§

impl Debug for Interner

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 Forget for Interner

§

impl Freeze for Interner

§

impl Move for Interner

§

impl RefUnwindSafe for Interner

§

impl Send for Interner
where RawVecInner: Send, Arc<str>: Send, RawTable<(Arc<str>, Symbol)>: Send,

§

impl Sync for Interner
where RawVecInner: Sync, Arc<str>: Sync, RawTable<(Arc<str>, Symbol)>: Sync,

§

impl Unpin for Interner
where *const u8 is !null: Unpin, Arc<str>: Unpin,

§

impl UnsafeUnpin for Interner

§

impl UnwindSafe for Interner

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.