use super::{ArrayLength, GenericArray}; use core::borrow::{Borrow, BorrowMut}; use core::cmp::Ordering; use core::fmt::{self, Debug}; use core::hash::{Hash, Hasher}; use functional::*; use sequence::*; impl Default for GenericArray where N: ArrayLength, { #[inline] fn default() -> Self { Self::generate(|_| T::default()) } } impl Clone for GenericArray where N: ArrayLength, { fn clone(&self) -> GenericArray { self.map(Clone::clone) } } impl Copy for GenericArray where N: ArrayLength, N::ArrayType: Copy, { } impl PartialEq for GenericArray where N: ArrayLength, { fn eq(&self, other: &Self) -> bool { **self == **other } } impl Eq for GenericArray where N: ArrayLength, { } impl PartialOrd for GenericArray where N: ArrayLength, { fn partial_cmp(&self, other: &GenericArray) -> Option { PartialOrd::partial_cmp(self.as_slice(), other.as_slice()) } } impl Ord for GenericArray where N: ArrayLength, { fn cmp(&self, other: &GenericArray) -> Ordering { Ord::cmp(self.as_slice(), other.as_slice()) } } impl Debug for GenericArray where N: ArrayLength, { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { self[..].fmt(fmt) } } impl Borrow<[T]> for GenericArray where N: ArrayLength, { #[inline(always)] fn borrow(&self) -> &[T] { &self[..] } } impl BorrowMut<[T]> for GenericArray where N: ArrayLength, { #[inline(always)] fn borrow_mut(&mut self) -> &mut [T] { &mut self[..] } } impl AsRef<[T]> for GenericArray where N: ArrayLength, { #[inline(always)] fn as_ref(&self) -> &[T] { &self[..] } } impl AsMut<[T]> for GenericArray where N: ArrayLength, { #[inline(always)] fn as_mut(&mut self) -> &mut [T] { &mut self[..] } } impl Hash for GenericArray where N: ArrayLength, { fn hash(&self, state: &mut H) where H: Hasher, { Hash::hash(&self[..], state) } } macro_rules! impl_from { ($($n: expr => $ty: ty),*) => { $( impl From<[T; $n]> for GenericArray { #[inline(always)] fn from(arr: [T; $n]) -> Self { unsafe { $crate::transmute(arr) } } } impl Into<[T; $n]> for GenericArray { #[inline(always)] fn into(self) -> [T; $n] { unsafe { $crate::transmute(self) } } } )* } } impl_from! { 1 => ::typenum::U1, 2 => ::typenum::U2, 3 => ::typenum::U3, 4 => ::typenum::U4, 5 => ::typenum::U5, 6 => ::typenum::U6, 7 => ::typenum::U7, 8 => ::typenum::U8, 9 => ::typenum::U9, 10 => ::typenum::U10, 11 => ::typenum::U11, 12 => ::typenum::U12, 13 => ::typenum::U13, 14 => ::typenum::U14, 15 => ::typenum::U15, 16 => ::typenum::U16, 17 => ::typenum::U17, 18 => ::typenum::U18, 19 => ::typenum::U19, 20 => ::typenum::U20, 21 => ::typenum::U21, 22 => ::typenum::U22, 23 => ::typenum::U23, 24 => ::typenum::U24, 25 => ::typenum::U25, 26 => ::typenum::U26, 27 => ::typenum::U27, 28 => ::typenum::U28, 29 => ::typenum::U29, 30 => ::typenum::U30, 31 => ::typenum::U31, 32 => ::typenum::U32 }