pub trait AtomTableOps {
// Required methods
fn count(&self) -> usize;
fn get_atom_string(
&self,
index: AtomIndex,
) -> Result<AtomRef<'_>, AtomError>;
fn ensure_atom(&self, atom_data: &[u8]) -> Result<AtomIndex, AtomError>;
fn find_atom(&self, atom_data: &[u8]) -> Result<AtomIndex, AtomError>;
fn atom_equals(&self, atom_index: AtomIndex, data: &[u8]) -> bool;
fn compare_atoms(&self, atom1: AtomIndex, atom2: AtomIndex) -> i32;
fn ensure_atoms_bulk(
&self,
atoms_data: &[u8],
count: usize,
encoding: EnsureAtomsOpt,
) -> Result<Vec<AtomIndex>, AtomError>;
// Provided methods
fn ensure_atom_str(&self, atom_str: &str) -> Result<AtomIndex, AtomError> { ... }
fn find_atom_str(&self, atom_str: &str) -> Result<AtomIndex, AtomError> { ... }
fn atom_equals_str(&self, atom_index: AtomIndex, s: &str) -> bool { ... }
}Expand description
Trait for atom table operations - the foundation of our generic design
Any implementation (real AtomVM, mock, in-memory, etc.) can provide these operations, making the entire system generic and testable.
Required Methods§
Sourcefn get_atom_string(&self, index: AtomIndex) -> Result<AtomRef<'_>, AtomError>
fn get_atom_string(&self, index: AtomIndex) -> Result<AtomRef<'_>, AtomError>
Get atom data by index
Sourcefn ensure_atom(&self, atom_data: &[u8]) -> Result<AtomIndex, AtomError>
fn ensure_atom(&self, atom_data: &[u8]) -> Result<AtomIndex, AtomError>
Ensure an atom exists in the table, creating it if necessary
Sourcefn find_atom(&self, atom_data: &[u8]) -> Result<AtomIndex, AtomError>
fn find_atom(&self, atom_data: &[u8]) -> Result<AtomIndex, AtomError>
Ensure an atom exists, but only if it already exists
Sourcefn atom_equals(&self, atom_index: AtomIndex, data: &[u8]) -> bool
fn atom_equals(&self, atom_index: AtomIndex, data: &[u8]) -> bool
Check if an atom equals the given byte string
Sourcefn compare_atoms(&self, atom1: AtomIndex, atom2: AtomIndex) -> i32
fn compare_atoms(&self, atom1: AtomIndex, atom2: AtomIndex) -> i32
Compare two atoms lexicographically
Sourcefn ensure_atoms_bulk(
&self,
atoms_data: &[u8],
count: usize,
encoding: EnsureAtomsOpt,
) -> Result<Vec<AtomIndex>, AtomError>
fn ensure_atoms_bulk( &self, atoms_data: &[u8], count: usize, encoding: EnsureAtomsOpt, ) -> Result<Vec<AtomIndex>, AtomError>
Bulk insert/lookup atoms from encoded atom data
Provided Methods§
Sourcefn ensure_atom_str(&self, atom_str: &str) -> Result<AtomIndex, AtomError>
fn ensure_atom_str(&self, atom_str: &str) -> Result<AtomIndex, AtomError>
Ensure an atom exists using a string slice
Sourcefn find_atom_str(&self, atom_str: &str) -> Result<AtomIndex, AtomError>
fn find_atom_str(&self, atom_str: &str) -> Result<AtomIndex, AtomError>
Find an atom using a string slice
Sourcefn atom_equals_str(&self, atom_index: AtomIndex, s: &str) -> bool
fn atom_equals_str(&self, atom_index: AtomIndex, s: &str) -> bool
Check if an atom equals the given string