diff --git a/src/lib.rs b/src/lib.rs index 372e961..35ae895 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,7 +6,13 @@ use std::ops::{ DerefMut, }; use std::slice; + +// extra traits use std::convert::From; +use std::borrow::{Borrow, BorrowMut}; +use std::convert::{AsRef, AsMut}; +use std::hash::{Hash, Hasher}; +use std::fmt; /// Make sure the non-nullable pointer optimization does not occur! enum Flag { @@ -364,6 +370,52 @@ impl iter::FromIterator for ArrayVec { } } +impl Clone for ArrayVec + where A::Item: Clone +{ + fn clone(&self) -> Self { + self.iter().cloned().collect() + } +} + +impl Hash for ArrayVec + where A::Item: Hash +{ + fn hash(&self, state: &mut H) { + Hash::hash(&**self, state) + } +} + +impl PartialEq for ArrayVec + where A::Item: PartialEq +{ + fn eq(&self, other: &Self) -> bool { + **self == **other + } +} + +impl Eq for ArrayVec where A::Item: Eq { } + +impl Borrow<[A::Item]> for ArrayVec { + fn borrow(&self) -> &[A::Item] { self } +} + +impl BorrowMut<[A::Item]> for ArrayVec { + fn borrow_mut(&mut self) -> &mut [A::Item] { self } +} + +impl AsRef<[A::Item]> for ArrayVec { + fn as_ref(&self) -> &[A::Item] { self } +} + +impl AsMut<[A::Item]> for ArrayVec { + fn as_mut(&mut self) -> &mut [A::Item] { self } +} + +impl fmt::Debug for ArrayVec where A::Item: fmt::Debug { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { (**self).fmt(f) } +} + #[test] fn test_simple() { use std::ops::Add; @@ -378,6 +430,8 @@ fn test_simple() { println!("{:?}", elt); } + println!("{:?}", vec); + let sum = vec.iter().map(|x| x.iter().fold(0, Add::add)).fold(0, Add::add); assert_eq!(sum, 13 + 87); let sum_len = vec.into_iter().map(|x| x.len()).fold(0, Add::add);