diff --git a/fixed_wide_vectors/src/macros/common.rs b/fixed_wide_vectors/src/macros/common.rs index df335fd..bb92dc7 100644 --- a/fixed_wide_vectors/src/macros/common.rs +++ b/fixed_wide_vectors/src/macros/common.rs @@ -81,5 +81,58 @@ macro_rules! impl_common { } } } + + impl From<[T; $size]> for $struct { + fn from(from: [T; $size]) -> Self { + let mut iterator = from.into_iter(); + + Self { + // SAFETY: We know the size of `from` so `iterator.next()` is always `Some(..)` + $( $field: unsafe { iterator.next().unwrap_unchecked() } ), + + } + } + } + + impl core::fmt::Debug for $struct { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let identifier = core::stringify!($struct); + + f.debug_struct(identifier) + $( .field( core::stringify!($field), &self.$field ) ) + + .finish() + } + } + + impl PartialEq for $struct { + fn eq(&self, other: &Self) -> bool { + $( self.$field == other.$field ) && + + } + } + + impl Eq for $struct { } + + impl core::hash::Hash for $struct { + fn hash(&self, state: &mut H) { + $( self.$field.hash(state); ) + + } + } + + impl Clone for $struct { + fn clone(&self) -> Self { + Self { + $( $field: self.$field.clone() ), + + } + } + } + + impl Copy for $struct { } + + impl Default for $struct { + fn default() -> Self { + Self { + $( $field: T::default() ), + + } + } + } } } diff --git a/fixed_wide_vectors/src/macros/vector.rs b/fixed_wide_vectors/src/macros/vector.rs index 09bfcbe..d3a69e7 100644 --- a/fixed_wide_vectors/src/macros/vector.rs +++ b/fixed_wide_vectors/src/macros/vector.rs @@ -5,59 +5,6 @@ macro_rules! impl_vector { ( $struct: ident { $($field: ident), + }, $size: expr ) => { $crate::impl_common!($struct { $($field), + }, $size); - impl From<[T; $size]> for $struct { - fn from(from: [T; $size]) -> Self { - let mut iterator = from.into_iter(); - - Self { - // SAFETY: We know the size of `from` so `iterator.next()` is always `Some(..)` - $( $field: unsafe { iterator.next().unwrap_unchecked() } ), + - } - } - } - - impl core::fmt::Debug for $struct { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - let identifier = core::stringify!($struct); - - f.debug_struct(identifier) - $( .field( core::stringify!($field), &self.$field ) ) + - .finish() - } - } - - impl PartialEq for $struct { - fn eq(&self, other: &Self) -> bool { - $( self.$field == other.$field ) && + - } - } - - impl Eq for $struct { } - - impl core::hash::Hash for $struct { - fn hash(&self, state: &mut H) { - $( self.$field.hash(state); ) + - } - } - - impl Clone for $struct { - fn clone(&self) -> Self { - Self { - $( $field: self.$field.clone() ), + - } - } - } - - impl Copy for $struct { } - - impl Default for $struct { - fn default() -> Self { - Self { - $( $field: T::default() ), + - } - } - } - impl $struct { pub fn min(self, rhs: Self) -> $struct { $struct{