pub struct AtomTable(/* private fields */);Expand description
A string uniquing table - only one copy of a string is stored and all attempts to add the same string again return the same atom. This table is intended to be easily shareable, so it utilizes interior mutability. UnsafeCell<> is safe because we never allow reference to it to escape.
Implementations§
Source§impl AtomTable
impl AtomTable
Sourcepub fn atom<V: Into<String> + AsRef<str>>(&self, value: V) -> Atom
pub fn atom<V: Into<String> + AsRef<str>>(&self, value: V) -> Atom
Add a string to the table and return its atom index. The same string always returns the same index.
pub fn try_str(&self, ident: Atom) -> Option<&str>
Sourcepub fn atom_u16<V: Into<Vec<u16>> + AsRef<[u16]>>(&self, value: V) -> AtomU16
pub fn atom_u16<V: Into<Vec<u16>> + AsRef<[u16]>>(&self, value: V) -> AtomU16
Add a string to the table and return its atom index. The same string always returns the same index.
pub fn try_str_u16(&self, ident: AtomU16) -> Option<&[u16]>
Sourcepub fn atom_bytes<V: Into<Vec<u8>> + AsRef<[u8]>>(&self, value: V) -> AtomBytes
pub fn atom_bytes<V: Into<Vec<u8>> + AsRef<[u8]>>(&self, value: V) -> AtomBytes
Add a byte string to the table and return its atom index. The same byte sequence always returns the same index. The bytes need not be valid UTF-8 (e.g., WTF-8 sequences encoding lone surrogates are accepted).
Sourcepub fn bytes(&self, ident: AtomBytes) -> &[u8] ⓘ
pub fn bytes(&self, ident: AtomBytes) -> &[u8] ⓘ
Return the contents of the specified atom bytes.
pub fn try_bytes(&self, ident: AtomBytes) -> Option<&[u8]>
Sourcepub fn in_debug_context<R, F: FnOnce() -> R>(&self, f: F) -> R
pub fn in_debug_context<R, F: FnOnce() -> R>(&self, f: F) -> R
Execute the callback in a context where this table is used for debug printing of atoms.
Sourcepub unsafe fn unsafe_set_debug_context(ptr: *const Self) -> *const Self
pub unsafe fn unsafe_set_debug_context(ptr: *const Self) -> *const Self
Set a table or nullptr as the Atom debug context. If non-null, debug printing of atoms will use it. Return the previous debug context.
§Safety
The table must not be destroyed or moved while it is set.