From cb1ce4bb232d75e9190b427c59e582f4677a98e1 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sat, 28 Aug 2021 18:06:59 +0200 Subject: [PATCH] use const generics to implement Chunk for all array sizes with min-const-generics stable we can implement `Chunk` for all sizes and not just up to 32 fixes #141 --- logos/src/source.rs | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/logos/src/source.rs b/logos/src/source.rs index 4ca46b00..0f0496ab 100644 --- a/logos/src/source.rs +++ b/logos/src/source.rs @@ -219,20 +219,11 @@ impl<'source> Chunk<'source> for u8 { } } -macro_rules! impl_array { - ($($size:expr),*) => ($( - impl<'source> Chunk<'source> for &'source [u8; $size] { - const SIZE: usize = $size; - - #[inline] - unsafe fn from_ptr(ptr: *const u8) -> Self { - &*(ptr as *const [u8; $size]) - } - } - )*); -} +impl<'source, const N: usize> Chunk<'source> for &'source [u8; N] { + const SIZE: usize = N; -impl_array!( - 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, - 27, 28, 29, 30, 31, 32 -); + #[inline] + unsafe fn from_ptr(ptr: *const u8) -> Self { + &*(ptr as *const [u8; N]) + } +}