use crate::{AsMutSlice, LinearMap};
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct ArrayMap<K: Eq, V: Sized + PartialEq, const LENGTH: usize> {
array: [(K, V); LENGTH],
}
impl<K: Eq, V: Sized + PartialEq, const LENGTH: usize> ArrayMap<K, V, LENGTH> {
pub const unsafe fn from_array_unchecked(array: [(K, V); LENGTH]) -> ArrayMap<K, V, LENGTH> {
ArrayMap { array }
}
pub const fn len(&self) -> usize {
self.array.len()
}
pub const fn is_empty(&self) -> bool {
self.len() == 0
}
}
impl<K: Eq, V: Sized + PartialEq, const LENGTH: usize> LinearMap<K, V> for ArrayMap<K, V, LENGTH> {
type Backing = [(K, V); LENGTH];
fn as_slice(&self) -> &[(K, V)] {
&self.array
}
fn into_inner(self) -> Self::Backing {
self.array
}
}
impl<K: Eq, V: Sized + PartialEq, const LENGTH: usize> AsMutSlice<K, V> for ArrayMap<K, V, LENGTH> {
fn as_mut_slice(&mut self) -> &mut [(K, V)] {
&mut self.array
}
}