From 328c5153b059f52397df2f209caac70f7499d5bf Mon Sep 17 00:00:00 2001 From: librelois <c@elo.tf> Date: Sun, 13 Jun 2021 17:34:20 +0200 Subject: [PATCH] feat(kv_typed): impl AsBytes for all SmallVec (use const generics) --- tools/kv_typed/src/as_bytes.rs | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/tools/kv_typed/src/as_bytes.rs b/tools/kv_typed/src/as_bytes.rs index 4e8cebe..20045fd 100644 --- a/tools/kv_typed/src/as_bytes.rs +++ b/tools/kv_typed/src/as_bytes.rs @@ -26,20 +26,16 @@ where } } -macro_rules! impl_as_bytes_for_smallvec { - ($($N:literal),*) => {$( - impl<T> AsBytes for SmallVec<[T; $N]> - where - T: zerocopy::AsBytes, - { - fn as_bytes<D, F: FnMut(&[u8]) -> D>(&self, mut f: F) -> D { - use zerocopy::AsBytes as _; - f((&self[..]).as_bytes()) - } - } - )*}; +impl<T, const N: usize> AsBytes for SmallVec<[T; N]> +where + T: zerocopy::AsBytes, + [T; N]: smallvec::Array<Item = T>, +{ + fn as_bytes<D, F: FnMut(&[u8]) -> D>(&self, mut f: F) -> D { + use zerocopy::AsBytes as _; + f((&self[..]).as_bytes()) + } } -impl_as_bytes_for_smallvec!(1, 2, 4, 8, 16, 32, 64); impl<T> AsBytes for BTreeSet<T> where -- GitLab