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

Auto Trait Implementations§

§

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

§

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 Twhere
T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere
T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere
T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere
U: From<T>,

const: unstable · 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 Twhere
U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere
U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.