pub struct EnumTable<K: Enumable, V, const N: usize> { /* private fields */ }Expand description
A table that associates each variant of an enumeration with a value.
EnumTable is a generic struct that uses an enumeration as keys and stores
associated values. It provides constant-time access to the values based on
the enumeration variant.
Implementations§
Source§impl<K: Enumable, V, const N: usize> EnumTable<K, V, N>
impl<K: Enumable, V, const N: usize> EnumTable<K, V, N>
Sourcepub const fn new(table: [(Discriminant<K>, V); N]) -> Self
pub const fn new(table: [(Discriminant<K>, V); N]) -> Self
Creates a new EnumTable with the given table of discriminants and values.
§Arguments
table- An array of tuples where each tuple contains a discriminant of an enumeration variant and its associated value.
Sourcepub fn new_with_fn(f: impl FnMut(&K) -> V) -> Self
pub fn new_with_fn(f: impl FnMut(&K) -> V) -> Self
Create a new EnumTable with a function that takes a variant and returns a value.
If you want to define it in const, use crate::et macro
Creates a new EnumTable using a function to generate values for each variant.
§Arguments
f- A function that takes a reference to an enumeration variant and returns a value to be associated with that variant.
Sourcepub const fn get(&self, variant: &K) -> &V
pub const fn get(&self, variant: &K) -> &V
Returns a reference to the value associated with the given enumeration variant.
§Arguments
variant- A reference to an enumeration variant.
Sourcepub const fn get_mut(&mut self, variant: &K) -> &mut V
pub const fn get_mut(&mut self, variant: &K) -> &mut V
Returns a mutable reference to the value associated with the given enumeration variant.
§Arguments
variant- A reference to an enumeration variant.
Trait Implementations§
impl<K: Copy + Enumable, V: Copy, const N: usize> Copy for EnumTable<K, V, N>
Auto Trait Implementations§
impl<K, V, const N: usize> Freeze for EnumTable<K, V, N>
impl<K, V, const N: usize> RefUnwindSafe for EnumTable<K, V, N>
impl<K, V, const N: usize> Send for EnumTable<K, V, N>where
V: Send,
impl<K, V, const N: usize> Sync for EnumTable<K, V, N>where
V: Sync,
impl<K, V, const N: usize> Unpin for EnumTable<K, V, N>where
V: Unpin,
impl<K, V, const N: usize> UnwindSafe for EnumTable<K, V, N>
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