Skip to content

Commit

Permalink
use const generics to implement Chunk for all array sizes (#221)
Browse files Browse the repository at this point in the history
with min-const-generics stable we can implement `Chunk` for all sizes and not just up to 32

fixes #141
  • Loading branch information
icewind1991 authored Jun 8, 2022
1 parent 89d9a8b commit 05de3cb
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions logos/src/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
}

0 comments on commit 05de3cb

Please sign in to comment.