pub struct StringInterner { /* private fields */ }Expand description
A string interner that stores unique strings and returns symbols
This is the single-threaded version. For concurrent access, use
ConcurrentStringInterner.
Implementations§
Source§impl StringInterner
impl StringInterner
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create a new string interner with pre-allocated capacity
Sourcepub fn get_or_intern(&mut self, s: &str) -> Symbol
pub fn get_or_intern(&mut self, s: &str) -> Symbol
Intern a string and return its symbol
If the string is already interned, returns the existing symbol. Otherwise, creates a new symbol for this string.
Sourcepub fn get_or_intern_owned(&mut self, s: String) -> Symbol
pub fn get_or_intern_owned(&mut self, s: String) -> Symbol
Intern an owned string (avoids clone if string is new)
Sourcepub fn get(&self, s: &str) -> Option<Symbol>
pub fn get(&self, s: &str) -> Option<Symbol>
Look up an already-interned string
Returns None if the string has not been interned
Sourcepub fn resolve(&self, symbol: Symbol) -> Option<&str>
pub fn resolve(&self, symbol: Symbol) -> Option<&str>
Resolve a symbol to its string
Returns None if the symbol is invalid
Sourcepub fn memory_usage(&self) -> usize
pub fn memory_usage(&self) -> usize
Get memory usage estimate in bytes
Trait Implementations§
Source§impl Debug for StringInterner
impl Debug for StringInterner
Auto Trait Implementations§
impl Freeze for StringInterner
impl RefUnwindSafe for StringInterner
impl Send for StringInterner
impl Sync for StringInterner
impl Unpin for StringInterner
impl UnwindSafe for StringInterner
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more