Skip to main content

OrdinalArrayMap

Struct OrdinalArrayMap 

Source
pub struct OrdinalArrayMap<K, V, const S: usize> { /* private fields */ }
Expand description

Map backed by an array, allocated on the stack.

Due to Rust limitations, the array size must be provided as a type parameter.

§Example

use ordinal_map::map::OrdinalArrayMap;
use ordinal_map::Ordinal;
#[derive(Ordinal)]
enum Weather {
    Sunny,
    Rainy,
    Snowy,
}

let mut map = OrdinalArrayMap::<_, _, { Weather::ORDINAL_SIZE }>::new();
map.insert(Weather::Sunny, "good");
map.insert(Weather::Rainy, "it depends");

This map is sparse (not every key has an associated value). For a total map, see OrdinalTotalMap and OrdinalTotalArrayMap.

Implementations§

Source§

impl<K: Ordinal, V, const S: usize> OrdinalArrayMap<K, V, S>

Source

pub fn new() -> Self

Create a new map.

Source

pub fn len(&self) -> usize

The number of elements in the map.

This operation is O(K::ORDINAL_SIZE).

Source

pub fn is_empty(&self) -> bool

Return true if the map container no elements.

Source

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

Look up a value by key.

Source

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

Look up a value by key.

Source

pub fn contains_key(&self, key: &K) -> bool

Check if the map contains a key.

Source

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

Insert a value into the map, returning the previous value if it existed.

Source

pub fn entry(&mut self, key: K) -> Entry<'_, K, V>

Get an entry in the map for the given key.

Source

pub fn remove(&mut self, key: &K) -> Option<V>

Remove a value from the map, returning it if it existed.

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 keys(&self) -> Keys<'_, K, V>

Iterate over the keys of the map.

Source

pub fn values(&self) -> Values<'_, K, V>

Iterate over the values of the map.

Source

pub fn values_mut(&mut self) -> ValuesMut<'_, K, V>

Iterate over the values of the map mutably.

Source

pub fn drain(&mut self) -> Drain<'_, K, V>

Remove all elements from the map.

Source

pub fn clear(&mut self)

Remove all elements from the map.

Source

pub fn retain<F>(&mut self, f: F)
where F: FnMut(K, &mut V) -> bool,

Retain only the elements specified by the predicate.

Trait Implementations§

Source§

impl<K: Ordinal, V: Clone, const S: usize> Clone for OrdinalArrayMap<K, V, S>

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, const S: usize> Debug for OrdinalArrayMap<K, V, S>

Source§

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

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

impl<K: Ordinal, V, const S: usize> Default for OrdinalArrayMap<K, V, S>

Source§

fn default() -> Self

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

impl<K: Ordinal, V, const S: usize> FromIterator<(K, V)> for OrdinalArrayMap<K, V, S>

Source§

fn from_iter<I: IntoIterator<Item = (K, V)>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<K: Ordinal, V, const S: usize> IntoIterator for OrdinalArrayMap<K, V, S>

Source§

type Item = (K, V)

The type of the elements being iterated over.
Source§

type IntoIter = IntoIterArray<K, V, S>

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, const S: usize> IntoIterator for &'a OrdinalArrayMap<K, V, S>

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<K, V, const S: usize> Freeze for OrdinalArrayMap<K, V, S>
where V: Freeze,

§

impl<K, V, const S: usize> RefUnwindSafe for OrdinalArrayMap<K, V, S>

§

impl<K, V, const S: usize> Send for OrdinalArrayMap<K, V, S>
where K: Send, V: Send,

§

impl<K, V, const S: usize> Sync for OrdinalArrayMap<K, V, S>
where K: Sync, V: Sync,

§

impl<K, V, const S: usize> Unpin for OrdinalArrayMap<K, V, S>
where K: Unpin, V: Unpin,

§

impl<K, V, const S: usize> UnsafeUnpin for OrdinalArrayMap<K, V, S>
where V: UnsafeUnpin,

§

impl<K, V, const S: usize> UnwindSafe for OrdinalArrayMap<K, V, S>
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> 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.