pub struct StringPool { /* private fields */ }Expand description
A string pool that deduplicates strings using reference counting.
Strings are stored as Arc<str>, allowing multiple references to
the same string without duplication. The pool maintains a weak
reference to each string, allowing unused strings to be garbage
collected.
Implementations§
Source§impl StringPool
impl StringPool
Sourcepub fn new() -> StringPool
pub fn new() -> StringPool
Creates a new empty string pool.
Sourcepub fn with_capacity(capacity: usize) -> StringPool
pub fn with_capacity(capacity: usize) -> StringPool
Creates a string pool with the specified capacity.
Sourcepub fn intern(&mut self, s: &str) -> Arc<str>
pub fn intern(&mut self, s: &str) -> Arc<str>
Interns a string, returning a reference-counted handle.
If the string already exists in the pool, returns a clone of
the existing Arc<str>. Otherwise, creates a new entry.
Sourcepub fn intern_string(&mut self, s: String) -> Arc<str>
pub fn intern_string(&mut self, s: String) -> Arc<str>
Interns a string from an owned String.
This is more efficient than intern when you already have a String,
as it avoids an extra allocation if the string is not already pooled.
Sourcepub fn memory_usage(&self) -> usize
pub fn memory_usage(&self) -> usize
Returns the memory usage of the pool in bytes (approximate).
This includes the HashMap overhead and the string data.
Sourcepub fn stats(&self) -> StringPoolStats
pub fn stats(&self) -> StringPoolStats
Returns statistics about the string pool.
Trait Implementations§
Source§impl Debug for StringPool
impl Debug for StringPool
Source§impl Default for StringPool
impl Default for StringPool
Source§fn default() -> StringPool
fn default() -> StringPool
Auto Trait Implementations§
impl Freeze for StringPool
impl RefUnwindSafe for StringPool
impl Send for StringPool
impl Sync for StringPool
impl Unpin for StringPool
impl UnsafeUnpin for StringPool
impl UnwindSafe for StringPool
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
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>
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>
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