pub struct StringPool { /* private fields */ }Expand description
A pool of interned strings.
Insert new strings with StringPool::insert to get an Atom that is
unique per string within the context of the associated pool.
Once you have interned a string into the pool and have its Atom, you can
get the interned string slice via &pool[atom] or pool.get(atom).
In general, there are no correctness protections against indexing into a
different StringPool from the one that the Atom was not allocated
inside. Doing so is memory safe but may panic or otherwise return incorrect
results.
Implementations§
Source§impl StringPool
impl StringPool
Sourcepub fn insert(&mut self, s: &str) -> Result<Atom, OutOfMemory>
pub fn insert(&mut self, s: &str) -> Result<Atom, OutOfMemory>
Insert a new string into this pool.
Sourcepub fn get_atom(&self, s: &str) -> Option<Atom>
pub fn get_atom(&self, s: &str) -> Option<Atom>
Get the Atom for the given string, if it has already been inserted
into this 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
Returns the “default value” for a type. Read more
Source§impl<'de> Deserialize<'de> for StringPool
impl<'de> Deserialize<'de> for StringPool
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Drop for StringPool
impl Drop for StringPool
Source§impl Index<&Atom> for StringPool
impl Index<&Atom> for StringPool
Source§impl Index<Atom> for StringPool
impl Index<Atom> for StringPool
Source§impl Serialize for StringPool
impl Serialize for StringPool
Source§impl TryClone for StringPool
impl TryClone for StringPool
Source§fn try_clone(&self) -> Result<Self, OutOfMemory>
fn try_clone(&self) -> Result<Self, OutOfMemory>
Attempt to clone
self, returning an error if any allocation fails
during cloning.Auto Trait Implementations§
impl Freeze for StringPool
impl RefUnwindSafe for StringPool
impl Send for StringPool
impl Sync for StringPool
impl Unpin 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
Mutably borrows from an owned value. Read more