StringInterner

Struct StringInterner 

Source
pub struct StringInterner<'src> { /* private fields */ }
Expand description

String interner for query compilation.

Interns strings during the analysis phase, then emits them as a contiguous byte pool with StringRef entries pointing into it.

Implementations§

Source§

impl<'src> StringInterner<'src>

Source

pub fn new() -> Self

Creates a new empty interner.

Source

pub fn intern(&mut self, s: &'src str) -> StringId

Interns a string, returning its ID.

If the string was previously interned, returns the existing ID.

Source

pub fn get(&self, s: &str) -> Option<StringId>

Returns the ID of a previously interned string, or None.

Source

pub fn resolve(&self, id: StringId) -> &'src str

Returns the string for a given ID.

§Panics

Panics if the ID is out of range.

Source

pub fn len(&self) -> usize

Returns the number of interned strings.

Source

pub fn is_empty(&self) -> bool

Returns true if no strings have been interned.

Source

pub fn iter(&self) -> impl Iterator<Item = (StringId, &'src str)> + '_

Returns an iterator over (id, string) pairs in ID order.

Source

pub fn total_bytes(&self) -> usize

Returns the total byte size needed for all strings.

Source

pub fn into_strings(self) -> Vec<&'src str>

Consumes the interner and returns strings in ID order.

Trait Implementations§

Source§

impl<'src> Debug for StringInterner<'src>

Source§

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

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

impl<'src> Default for StringInterner<'src>

Source§

fn default() -> StringInterner<'src>

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

Auto Trait Implementations§

§

impl<'src> Freeze for StringInterner<'src>

§

impl<'src> RefUnwindSafe for StringInterner<'src>

§

impl<'src> Send for StringInterner<'src>

§

impl<'src> Sync for StringInterner<'src>

§

impl<'src> Unpin for StringInterner<'src>

§

impl<'src> UnwindSafe for StringInterner<'src>

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.