pub struct InternPool { /* private fields */ }Expand description
The raw storage for interned strings.
stringsis append-only; indices are stable for the lifetime of the pool.mapmaps each string’s content to its index for O(1) deduplication.static_ptrscaches the&'static strobtained by leaking each string exactly once, so subsequentresolvecalls are O(1) slice lookups.
Implementations§
Source§impl InternPool
impl InternPool
Sourcepub fn intern_str(&mut self, s: &str) -> u32
pub fn intern_str(&mut self, s: &str) -> u32
Interns s, returning a stable index.
If s is already present the existing index is returned without
any allocation. Otherwise a new String is pushed and indexed.
Sourcepub fn resolve_str(&mut self, id: u32) -> Option<&'static str>
pub fn resolve_str(&mut self, id: u32) -> Option<&'static str>
Resolves index id to a &'static str.
The string is leaked into a Box<str> on the first call for id and
the resulting pointer is cached. Subsequent calls for the same id
return the cached pointer without any allocation.
Returns None if id is out of range.
Sourcepub fn total_bytes(&self) -> usize
pub fn total_bytes(&self) -> usize
Returns the total byte count of all interned strings.
Sourcepub fn stats(&self) -> InternPoolStats
pub fn stats(&self) -> InternPoolStats
Returns a InternPoolStats snapshot.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for InternPool
impl RefUnwindSafe for InternPool
impl Send for InternPool
impl Sync for InternPool
impl Unpin for InternPool
impl UnsafeUnpin for InternPool
impl UnwindSafe for InternPool
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