Skip to main content

AtomTable

Struct AtomTable 

Source
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

Source

pub fn new() -> AtomTable

Create a new empty atom table.

Source

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.

Source

pub fn str(&self, ident: Atom) -> &str

Return the contents of the specified atom.

Source

pub fn try_str(&self, ident: Atom) -> Option<&str>

Source

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.

Source

pub fn str_u16(&self, ident: AtomU16) -> &[u16]

Return the contents of the specified atom.

Source

pub fn try_str_u16(&self, ident: AtomU16) -> Option<&[u16]>

Source

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).

Source

pub fn bytes(&self, ident: AtomBytes) -> &[u8]

Return the contents of the specified atom bytes.

Source

pub fn try_bytes(&self, ident: AtomBytes) -> Option<&[u8]>

Source

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.

Source

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.

Trait Implementations§

Source§

impl Debug for AtomTable

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for AtomTable

Source§

fn default() -> AtomTable

Returns the “default value” for a type. Read more
Source§

impl Index<Atom> for AtomTable

Source§

type Output = str

The returned type after indexing.
Source§

fn index(&self, index: Atom) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<AtomBytes> for AtomTable

Source§

type Output = [u8]

The returned type after indexing.
Source§

fn index(&self, index: AtomBytes) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<AtomU16> for AtomTable

Source§

type Output = [u16]

The returned type after indexing.
Source§

fn index(&self, index: AtomU16) -> &Self::Output

Performs the indexing (container[index]) operation. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.