Skip to main content

SymbolTable

Struct SymbolTable 

Source
pub struct SymbolTable<Id, T> { /* private fields */ }
Expand description

A symbol table mapping IDs to values.

Used for roles, sections, parameters, materials, and outputs. Provides O(1) lookup by ID and iteration in insertion order.

Implementations§

Source§

impl<Id: Eq + Hash + Clone, T> SymbolTable<Id, T>

Source

pub fn new() -> Self

Create a new empty symbol table.

Source

pub fn insert(&mut self, id: Id, value: T) -> Result<(), Id>

Insert an item, returning an error if the ID already exists.

Source

pub fn insert_or_replace(&mut self, id: Id, value: T)

Insert an item, overwriting if it already exists.

Source

pub fn get(&self, id: &Id) -> Option<&T>

Get an item by ID.

Source

pub fn get_mut(&mut self, id: &Id) -> Option<&mut T>

Get a mutable reference to an item by ID.

Source

pub fn contains(&self, id: &Id) -> bool

Check if an ID exists in the table.

Source

pub fn iter(&self) -> impl Iterator<Item = (&Id, &T)>

Iterate over all (ID, value) pairs in insertion order.

Source

pub fn values(&self) -> impl Iterator<Item = &T>

Iterate over all values in insertion order.

Source

pub fn keys(&self) -> impl Iterator<Item = &Id>

Iterate over all IDs in insertion order.

Source

pub fn len(&self) -> usize

Get the number of items.

Source

pub fn is_empty(&self) -> bool

Check if the table is empty.

Trait Implementations§

Source§

impl<Id: Clone, T: Clone> Clone for SymbolTable<Id, T>

Source§

fn clone(&self) -> SymbolTable<Id, T>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Id: Debug, T: Debug> Debug for SymbolTable<Id, T>

Source§

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

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

impl<Id: Eq + Hash + Clone, T> Default for SymbolTable<Id, T>

Source§

fn default() -> Self

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

impl<Id: Eq + Hash + Clone, T> FromIterator<(Id, T)> for SymbolTable<Id, T>

Source§

fn from_iter<I: IntoIterator<Item = (Id, T)>>(iter: I) -> Self

Creates a value from an iterator. Read more

Auto Trait Implementations§

§

impl<Id, T> Freeze for SymbolTable<Id, T>
where IndexMap<Id, T>: Freeze,

§

impl<Id, T> RefUnwindSafe for SymbolTable<Id, T>
where IndexMap<Id, T>: RefUnwindSafe,

§

impl<Id, T> Send for SymbolTable<Id, T>
where IndexMap<Id, T>: Send,

§

impl<Id, T> Sync for SymbolTable<Id, T>
where IndexMap<Id, T>: Sync,

§

impl<Id, T> Unpin for SymbolTable<Id, T>
where IndexMap<Id, T>: Unpin,

§

impl<Id, T> UnsafeUnpin for SymbolTable<Id, T>
where IndexMap<Id, T>: UnsafeUnpin,

§

impl<Id, T> UnwindSafe for SymbolTable<Id, T>
where IndexMap<Id, T>: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.