pub struct StringInterner { /* private fields */ }Expand description
Intern table mapping strings to unique u32 handles. Thread-safe for reads; mutation requires &mut.
Implementations§
Source§impl StringInterner
impl StringInterner
pub fn new() -> Self
pub fn with_capacity(cap: usize) -> Self
Sourcepub fn get_or_intern(&mut self, s: &str) -> InternedStr
pub fn get_or_intern(&mut self, s: &str) -> InternedStr
Intern s, returning its handle. Idempotent.
Sourcepub fn resolve(&self, idx: InternedStr) -> &str
pub fn resolve(&self, idx: InternedStr) -> &str
Resolve handle back to string. Panics if idx out of range.
Sourcepub fn try_resolve(&self, idx: InternedStr) -> Option<&str>
pub fn try_resolve(&self, idx: InternedStr) -> Option<&str>
Try to resolve without panicking.
Sourcepub fn lookup(&self, s: &str) -> Option<InternedStr>
pub fn lookup(&self, s: &str) -> Option<InternedStr>
Lookup without interning. Returns None if not present.
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Auto Trait Implementations§
impl Freeze for StringInterner
impl RefUnwindSafe for StringInterner
impl Send for StringInterner
impl Sync for StringInterner
impl Unpin for StringInterner
impl UnsafeUnpin 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