Skip to content
Snippets Groups Projects
Commit de0a303a authored by Éloïs's avatar Éloïs
Browse files

feat(kv_typed): impl FromBytes for all SmallVec (use const generics)

parent 06eca4f3
No related branches found
No related tags found
No related merge requests found
......@@ -55,23 +55,19 @@ impl FromBytes for String {
}
}
macro_rules! impl_from_bytes_for_smallvec {
($($N:literal),*) => {$(
impl<T> FromBytes for SmallVec<[T; $N]>
impl<T, const N: usize> FromBytes for SmallVec<[T; N]>
where
T: Copy + zerocopy::FromBytes,
[T; N]: smallvec::Array<Item = T>,
{
type Err = LayoutVerifiedErr;
fn from_bytes(bytes: &[u8]) -> Result<Self, Self::Err> {
let layout_verified = zerocopy::LayoutVerified::<_, [T]>::new_slice(bytes)
.ok_or_else(|| LayoutVerifiedErr(stringify!(T)).into())?;
.ok_or(LayoutVerifiedErr(stringify!(T)))?;
Ok(SmallVec::from_slice(layout_verified.into_slice()))
}
}
)*};
}
impl_from_bytes_for_smallvec!(1, 2, 4, 8, 16, 32, 64);
impl<T> FromBytes for Vec<T>
where
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment