use super::vecs::{MutableZeroVecLike, ZeroVecLike};
use crate::ule::*;
use crate::vecs::{FlexZeroSlice, FlexZeroVec};
use crate::vecs::{VarZeroSlice, VarZeroVec};
use crate::zerovec::{ZeroSlice, ZeroVec};
use alloc::boxed::Box;
#[allow(clippy::upper_case_acronyms)] pub trait ZeroMapKV<'a> {
type Container: MutableZeroVecLike<
'a,
Self,
SliceVariant = Self::Slice,
GetType = Self::GetType,
OwnedType = Self::OwnedType,
> + Sized;
type Slice: ZeroVecLike<Self, GetType = Self::GetType> + ?Sized;
type GetType: ?Sized + 'static;
type OwnedType: 'static;
}
macro_rules! impl_sized_kv {
($ty:ident) => {
impl<'a> ZeroMapKV<'a> for $ty {
type Container = ZeroVec<'a, $ty>;
type Slice = ZeroSlice<$ty>;
type GetType = <$ty as AsULE>::ULE;
type OwnedType = $ty;
}
};
}
impl_sized_kv!(u8);
impl_sized_kv!(u16);
impl_sized_kv!(u32);
impl_sized_kv!(u64);
impl_sized_kv!(u128);
impl_sized_kv!(i8);
impl_sized_kv!(i16);
impl_sized_kv!(i32);
impl_sized_kv!(i64);
impl_sized_kv!(i128);
impl_sized_kv!(char);
impl_sized_kv!(f32);
impl_sized_kv!(f64);
impl<'a> ZeroMapKV<'a> for usize {
type Container = FlexZeroVec<'a>;
type Slice = FlexZeroSlice;
type GetType = [u8];
type OwnedType = usize;
}
impl<'a, T> ZeroMapKV<'a> for Option<T>
where
Option<T>: AsULE + 'static,
{
type Container = ZeroVec<'a, Option<T>>;
type Slice = ZeroSlice<Option<T>>;
type GetType = <Option<T> as AsULE>::ULE;
type OwnedType = Option<T>;
}
impl<'a, T> ZeroMapKV<'a> for OptionVarULE<T>
where
T: VarULE + ?Sized,
{
type Container = VarZeroVec<'a, OptionVarULE<T>>;
type Slice = VarZeroSlice<OptionVarULE<T>>;
type GetType = OptionVarULE<T>;
type OwnedType = Box<OptionVarULE<T>>;
}
impl<'a> ZeroMapKV<'a> for str {
type Container = VarZeroVec<'a, str>;
type Slice = VarZeroSlice<str>;
type GetType = str;
type OwnedType = Box<str>;
}
impl<'a, T> ZeroMapKV<'a> for [T]
where
T: ULE + AsULE<ULE = T>,
{
type Container = VarZeroVec<'a, [T]>;
type Slice = VarZeroSlice<[T]>;
type GetType = [T];
type OwnedType = Box<[T]>;
}
impl<'a, T, const N: usize> ZeroMapKV<'a> for [T; N]
where
T: AsULE + 'static,
{
type Container = ZeroVec<'a, [T; N]>;
type Slice = ZeroSlice<[T; N]>;
type GetType = [T::ULE; N];
type OwnedType = [T; N];
}
impl<'a, T> ZeroMapKV<'a> for ZeroSlice<T>
where
T: AsULE + 'static,
{
type Container = VarZeroVec<'a, ZeroSlice<T>>;
type Slice = VarZeroSlice<ZeroSlice<T>>;
type GetType = ZeroSlice<T>;
type OwnedType = Box<ZeroSlice<T>>;
}