use crate::prelude::*;
#[inline(always)]
pub fn slice2array<T, const N: usize>(slice: &[T]) -> Result<[T; N]>
where
T: Copy,
{
slice.try_into().map_err(|_| Error::MismatchedLength { expect: N })
}
#[test]
fn slice2array_should_work() {
assert_eq!(slice2array::<_, 8>(&[0; 8]), Ok([0; 8]));
}
pub fn slice2array_ref<T, const N: usize>(slice: &[T]) -> Result<&[T; N]>
where
T: Copy,
{
slice.try_into().map_err(|_| Error::MismatchedLength { expect: N })
}
pub fn slice_n_into<T, V, const N: usize>(slice: &[T]) -> Result<V>
where
T: Copy,
V: From<[T; N]>,
{
Ok(slice2array(slice)?.into())
}
#[test]
fn slice_n_into_should_work() {
assert_eq!(slice_n_into::<u8, Ljfn, 17>(b"Love Jane Forever"), Ok(Ljfn(*b"Love Jane Forever")));
}