use crate::{MetadataCreationFailure, Thinnable};
use core::convert::{TryFrom, TryInto};
pub unsafe trait SliceLength: Sized + TryFrom<usize> + TryInto<usize> {}
pub type ThinnableSlice<T, M, const N: usize> = Thinnable<[T; N], [T], M>;
impl<T, M: SliceLength, const N: usize> ThinnableSlice<T, M, N> {
#[inline(always)]
pub fn try_slice(data: [T; N]) -> Result<Self, MetadataCreationFailure<[T], M>> {
unsafe { Self::try_new(data) }
}
}
macro_rules! thinnable_slices {
($($alias:ident($ty:ty))+) => {$(
#[doc = concat!("Convenient alias for slices with length stored in a `", stringify!($ty), "`.")]
pub type $alias<T, const N: usize> = ThinnableSlice<T, $ty, N>;
unsafe impl SliceLength for $ty {}
)+};
}
thinnable_slices! {
ThinnableSliceU8(u8)
ThinnableSliceU16(u16)
ThinnableSliceU32(u32)
}