pub struct Interner { /* private fields */ }Expand description
Thread-safe string interner — maps Arc<str> ↔ u32 IDs.
Interning replaces repeated Arc<str> pointers (16 bytes each) with 4-byte
u32 IDs. The same string always maps to the same ID for the lifetime of
this interner.
§Concurrency
- Fast path (already interned): lock-free read from the
DashMap. - Slow path (new string): acquires a
RwLockwrite guard, re-checks under the lock to handle races, then assigns an ID atomically. get(id)acquires a read guard; multiple concurrent readers are allowed.
Implementations§
Source§impl Interner
impl Interner
Sourcepub fn intern(&self, s: Arc<str>) -> u32
pub fn intern(&self, s: Arc<str>) -> u32
Intern s and return its ID. Idempotent: the same string always returns
the same ID.
Sourcepub fn intern_str(&self, s: &str) -> u32
pub fn intern_str(&self, s: &str) -> u32
Intern from a &str without allocating an Arc when the string is
already interned.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Interner
impl !RefUnwindSafe for Interner
impl Send for Interner
impl Sync for Interner
impl Unpin for Interner
impl UnsafeUnpin for Interner
impl UnwindSafe for Interner
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