pub struct EnumTable<K, V> { /* private fields */ }
Expand description

A key-value table optimized for Enums used as keys. Initialized with V’s Default values.

use enum_collections::{EnumTable, Enumerated};
#[derive(Enumerated)]
enum Letter {
    A,
    B,
}

let mut map: EnumTable<Letter, u8> = EnumTable::new();
map[Letter::A] = 42;
assert_eq!(42u8, map[Letter::A]);
assert_eq!(u8::default(), map[Letter::B]);

Implementations§

source§

impl<K, V> EnumTable<K, V>
where K: Enumerated,

source

pub fn from_fn(cb: impl FnMut(&K) -> V) -> Self

source§

impl<K, V> EnumTable<K, V>
where K: Enumerated, V: Default,

source

pub fn new() -> Self

Creates a new EnumTable, with pre-allocated space for all keys of the enum K. With the underlying array righsized, no resizing is further required. All values are initialized with V’s Default value.

source

pub fn reset(&mut self, key: K)

Resets value of type V corresponding to key to its default by calling its Default trait implementation.

§Args
  • key - The instance of K pointing at the slot to reset to default.

Trait Implementations§

source§

impl<K, V> Debug for EnumTable<K, V>
where K: Enumerated + Debug, V: Debug,

source§

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

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

impl<K, V> Default for EnumTable<K, V>
where K: Enumerated, V: Default,

source§

fn default() -> Self

Constructs a new instance, capable of holding all values of key K without further resizing.

source§

impl<F, K, V> From<F> for EnumTable<K, V>
where K: Enumerated, F: FnMut(&K) -> V,

source§

fn from(cb: F) -> Self

Converts to this type from the input type.
source§

impl<K, V> Index<K> for EnumTable<K, V>
where K: Enumerated, V: Default,

§

type Output = V

The returned type after indexing.
source§

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

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

impl<K, V> IndexMut<K> for EnumTable<K, V>
where K: Enumerated, V: Default,

source§

fn index_mut(&mut self, key: K) -> &mut Self::Output

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

impl<K, V> PartialEq for EnumTable<K, V>
where K: Enumerated, V: Default + PartialEq,

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<K, V> Eq for EnumTable<K, V>
where K: Enumerated, V: Default + Eq,

Auto Trait Implementations§

§

impl<K, V> RefUnwindSafe for EnumTable<K, V>

§

impl<K, V> Send for EnumTable<K, V>
where K: Send, V: Send,

§

impl<K, V> Sync for EnumTable<K, V>
where K: Sync, V: Sync,

§

impl<K, V> Unpin for EnumTable<K, V>
where K: Unpin,

§

impl<K, V> UnwindSafe for EnumTable<K, V>
where K: UnwindSafe, V: 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> 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>,

§

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>,

§

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.