diff --git a/hybrid-array/src/lib.rs b/hybrid-array/src/lib.rs index 3306c24e..79b79b49 100644 --- a/hybrid-array/src/lib.rs +++ b/hybrid-array/src/lib.rs @@ -29,6 +29,9 @@ pub use typenum::consts; use core::{ array::{IntoIter, TryFromSliceError}, borrow::{Borrow, BorrowMut}, + cmp::Ordering, + fmt::{self, Debug}, + hash::{Hash, Hasher}, ops::{Deref, DerefMut, Index, IndexMut, Range}, slice::{Iter, IterMut}, }; @@ -38,7 +41,6 @@ use typenum::Unsigned; /// /// Provides the flexibility of typenum-based expressions while also /// allowing interoperability and a transition path to const generics. -#[derive(Debug, Eq, Hash, PartialEq, PartialOrd, Ord)] #[repr(transparent)] pub struct Array(pub U::ArrayType); @@ -188,6 +190,17 @@ where { } +impl Debug for Array +where + T: Debug, + U: ArraySize, + U::ArrayType: Debug, +{ + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_tuple("Array").field(&self.0).finish() + } +} + impl Default for Array where T: Default, @@ -220,6 +233,13 @@ where } } +impl Eq for Array +where + T: Eq, + U: ArraySize, +{ +} + impl From<[T; N]> for Array where Self: ArrayOps, @@ -253,6 +273,17 @@ where } } +impl Hash for Array +where + T: Hash, + U: ArraySize, +{ + #[inline] + fn hash(&self, state: &mut H) { + self.0.as_ref().hash(state); + } +} + impl Index for Array where [T]: Index, @@ -277,6 +308,36 @@ where } } +impl PartialEq for Array +where + T: PartialEq, + U: ArraySize, +{ + fn eq(&self, other: &Self) -> bool { + self.0.as_ref().eq(other.0.as_ref()) + } +} + +impl PartialOrd for Array +where + T: PartialOrd, + U: ArraySize, +{ + fn partial_cmp(&self, other: &Self) -> Option { + self.0.as_ref().partial_cmp(other.0.as_ref()) + } +} + +impl Ord for Array +where + T: Ord, + U: ArraySize, +{ + fn cmp(&self, other: &Self) -> Ordering { + self.0.as_ref().cmp(other.0.as_ref()) + } +} + impl<'a, T, U> TryFrom<&'a [T]> for Array where T: Copy,