Skip to content

Commit

Permalink
Use const generics for array TypeInfo impls (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
ascjones authored Mar 25, 2021
1 parent 22c430a commit c51a1d5
Showing 1 changed file with 5 additions and 20 deletions.
25 changes: 5 additions & 20 deletions src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,29 +61,14 @@ impl_metadata_for_primitives!(
i128 => TypeDefPrimitive::I128,
);

macro_rules! impl_metadata_for_array {
( $( $n:expr )* ) => {
$(
impl<T: TypeInfo + 'static> TypeInfo for [T; $n] {
type Identity = Self;

fn type_info() -> Type {
TypeDefArray::new($n, MetaType::new::<T>()).into()
}
}
)*
impl<T: TypeInfo + 'static, const N: usize> TypeInfo for [T; N] {
type Identity = Self;

fn type_info() -> Type {
TypeDefArray::new(N as u32, MetaType::new::<T>()).into()
}
}

#[rustfmt::skip]
impl_metadata_for_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
40 48 56 64 72 96 128 160 192 224 256
);

macro_rules! impl_metadata_for_tuple {
( $($ty:ident),* ) => {
impl<$($ty),*> TypeInfo for ($($ty,)*)
Expand Down

0 comments on commit c51a1d5

Please sign in to comment.