Skip to main content

OrdinalTotalMap

Struct OrdinalTotalMap 

Source
pub struct OrdinalTotalMap<T, V> { /* private fields */ }
Expand description

Map implementation where all values must be initialized at creation.

This version of map allocates values on the heap in a single contiguous block. For a version that doesn’t require heap allocation, see InitArrayMap.

Implementations§

Source§

impl<K: Ordinal, V> OrdinalTotalMap<K, V>

Source

pub fn try_new<E>(init: impl FnMut(K) -> Result<V, E>) -> Result<Self, E>

Create a new map by initializing each value with a function.

Source

pub fn new(init: impl FnMut(K) -> V) -> Self

Create a new map by initializing each value with a function.

Source

pub const fn len(&self) -> usize

Returns the number of elements in the map, which is always equal to K::ORDINAL_SIZE.

Source

pub const fn is_empty(&self) -> bool

Return true if the map container no elements. This is only if <K> is empty.

Source

pub fn get<'a>(&'a self, key: &K) -> &'a V

Returns a reference to the value corresponding to the key.

Source

pub fn get_mut<'a>(&'a mut self, key: &K) -> &'a mut V

Returns a mutable reference to the value corresponding to the key.

Source

pub fn keys(&self) -> OrdinalValues<K>

Iterate keys of the map, which is equivalent to iterating all possible values of K.

Source

pub fn into_keys(self) -> OrdinalValues<K>

Iterate values of the map, which is equivalent to iterating all possible values of K.

Source

pub fn values<'a>(&'a self) -> Iter<'a, V>

Iterate values of the map.

Source

pub fn values_mut<'a>(&'a mut self) -> IterMut<'a, V>

Iterate mutable references to values of the map.

Source

pub fn into_values(self) -> Box<[V]>

Obtain the values from the map.

Source

pub fn iter<'a>(&'a self) -> Iter<'a, K, V>

Iterate over the map.

Source

pub fn iter_mut<'a>(&'a mut self) -> IterMut<'a, K, V>

Iterate over the map mutably.

Source

pub fn insert(&mut self, key: K, value: V) -> V

Insert a value into the map, returning the previous value.

Trait Implementations§

Source§

impl<K, V: Clone> Clone for OrdinalTotalMap<K, V>

Source§

fn clone(&self) -> Self

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<K: Ordinal + Debug, V: Debug> Debug for OrdinalTotalMap<K, V>

Source§

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

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

impl<K: Ordinal, V: Default> Default for OrdinalTotalMap<K, V>

Source§

fn default() -> Self

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

impl<'a, K: Ordinal, V> Index<&'a K> for OrdinalTotalMap<K, V>

Source§

type Output = V

The returned type after indexing.
Source§

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

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

impl<'a, K: Ordinal, V> IndexMut<&'a K> for OrdinalTotalMap<K, V>

Source§

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

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

impl<K: Ordinal, V> IntoIterator for OrdinalTotalMap<K, V>

Source§

type Item = (K, V)

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<K, V>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a, K: Ordinal, V> IntoIterator for &'a OrdinalTotalMap<K, V>

Source§

type Item = (K, &'a V)

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, K, V>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<T, V> Freeze for OrdinalTotalMap<T, V>

§

impl<T, V> RefUnwindSafe for OrdinalTotalMap<T, V>

§

impl<T, V> Send for OrdinalTotalMap<T, V>
where T: Send, V: Send,

§

impl<T, V> Sync for OrdinalTotalMap<T, V>
where T: Sync, V: Sync,

§

impl<T, V> Unpin for OrdinalTotalMap<T, V>
where T: Unpin,

§

impl<T, V> UnsafeUnpin for OrdinalTotalMap<T, V>

§

impl<T, V> UnwindSafe for OrdinalTotalMap<T, V>
where T: 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> 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> 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 = 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>,

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.