diff --git a/.travis.yml b/.travis.yml index 99758624ca3bedf7a1bf9e351e290d2cff858366..0b583f1f19ff922356e1aab7b221820ad3b19142 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,8 +6,7 @@ matrix: rust: nightly - env: TARGET=thumbv6m-none-eabi - # work around rust-lang/rust#45802 - rust: nightly-2017-11-01 + rust: nightly addons: apt: sources: @@ -34,7 +33,11 @@ script: after_script: set +e -cache: cargo +cache: + cargo: true + directories: + - $HOME/.xargo + before_cache: # Travis can't cache files that are not readable by "others" - chmod -R a+r $HOME/.cargo diff --git a/src/vec.rs b/src/vec.rs index c1538964f038f4322021defe12c50b400fb74a5f..99abad37de095a42325914006ca532678be6742c 100644 --- a/src/vec.rs +++ b/src/vec.rs @@ -1,5 +1,5 @@ use core::marker::{PhantomData, Unsize}; -use core::{ops, ptr, slice}; +use core::{fmt, ops, ptr, slice}; use untagged_option::UntaggedOption; @@ -94,9 +94,10 @@ where /// new_len is less than len, the Vec is simply truncated. /// /// See also [`resize_default`]. - pub fn resize(&mut self, new_len: usize, value: T) - -> Result<(), BufferFullError> - where T: Clone { + pub fn resize(&mut self, new_len: usize, value: T) -> Result<(), BufferFullError> + where + T: Clone, + { if new_len > self.capacity() { return Err(BufferFullError); } @@ -119,13 +120,25 @@ where /// If `new_len` is less than `len`, the `Vec` is simply truncated. /// /// See also [`resize`]. - pub fn resize_default(&mut self, new_len: usize) - -> Result<(), BufferFullError> - where T: Clone + Default { + pub fn resize_default(&mut self, new_len: usize) -> Result<(), BufferFullError> + where + T: Clone + Default, + { self.resize(new_len, T::default()) } } +impl<T, A> fmt::Debug for Vec<T, A> +where + A: Unsize<[T]>, + T: fmt::Debug, +{ + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let slice: &[T] = &**self; + slice.fmt(f) + } +} + impl<T, A> Drop for Vec<T, A> where A: Unsize<[T]>, @@ -159,6 +172,24 @@ where } } +impl<T, A, B> PartialEq<Vec<T, B>> for Vec<T, A> +where + A: Unsize<[T]>, + B: Unsize<[T]>, + T: PartialEq, +{ + fn eq(&self, rhs: &Vec<T, B>) -> bool { + PartialEq::eq(&**self, &**rhs) + } +} + +impl<T, A> Eq for Vec<T, A> +where + A: Unsize<[T]>, + T: Eq, +{ +} + impl<T, A> ops::Deref for Vec<T, A> where A: Unsize<[T]>, @@ -225,6 +256,19 @@ mod tests { assert_eq!(unsafe { COUNT }, 0); } + #[test] + fn eq() { + let mut xs: Vec<i32, [i32; 4]> = Vec::new(); + let mut ys: Vec<i32, [i32; 8]> = Vec::new(); + + assert_eq!(xs, ys); + + xs.push(1).unwrap(); + ys.push(1).unwrap(); + + assert_eq!(xs, ys); + } + #[test] fn full() { let mut v: Vec<i32, [i32; 4]> = Vec::new(); @@ -322,7 +366,6 @@ mod tests { v.resize(2, 0).unwrap(); assert_eq!(v.len(), 2); - // Shrink by 2 v.resize(0, 0).unwrap(); assert_eq!(v.len(), 0);