pub struct SymTab { /* private fields */ }
Expand description
A simple symbol table that maps string names to integer values.
Each inserted name receives a stable index corresponding to its insertion order. Re-inserting the same name returns the existing index.
Implementations§
Source§impl SymTab
impl SymTab
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of entries currently stored in the symbol table.
Each entry corresponds to a unique symbol (e.g., variable or identifier) that has been interned.
§Example
let mut symtab = SymTab::new();
assert_eq!(symtab.len(), 0);
symtab.intern("foo");
assert_eq!(symtab.len(), 1);
symtab.intern("baz");
assert_eq!(symtab.len(), 2);
symtab.intern("foo");
assert_eq!(symtab.len(), 2);
Sourcepub fn intern(&mut self, name: impl AsRef<str>) -> usize
pub fn intern(&mut self, name: impl AsRef<str>) -> usize
Inserts the given name if it doesn’t exist and returns its index.
If the name already exists, this returns the existing index without modifying the stored value.
§Examples
let mut st = SymTab::new();
let i = st.intern("a");
assert_eq!(i, 0);
assert_eq!(st.intern("a"), 0); // existing index
Trait Implementations§
Auto Trait Implementations§
impl Freeze for SymTab
impl RefUnwindSafe for SymTab
impl Send for SymTab
impl Sync for SymTab
impl Unpin for SymTab
impl UnwindSafe for SymTab
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