diff --git a/src/impls.rs b/src/impls.rs index 64ae08b..6e77888 100644 --- a/src/impls.rs +++ b/src/impls.rs @@ -1,4 +1,4 @@ -//! Implements `Debug`, and `PartialEq` for various list-like types. +//! Implements `Debug`, `Default`, `Extend`, and `Deref`. Also implements `PartialEq` for various list-like types. use crate::{Vec, Extra}; @@ -30,9 +30,9 @@ impl, U: ?Sized> PartialEq> for Vec { impl Eq for Vec {} -// Vec == &[U] -impl, U> PartialEq<&[U]> for Vec { - fn eq(&self, other: &&[U]) -> bool { +// Vec == [U] +impl, U> PartialEq<[U]> for Vec { + fn eq(&self, other: &[U]) -> bool { if self.len != other.len() { return false } for (el, el2) in self.iter().zip(other.iter()) { if el != el2 { return false } @@ -41,24 +41,80 @@ impl, U> PartialEq<&[U]> for Vec { } } +// [U] == Vec +impl, U> PartialEq> for [U] { + fn eq(&self, other: &Vec) -> bool { + other == self + } +} + +// Vec == &[U] +impl, U> PartialEq<&[U]> for Vec { + fn eq(&self, other: &&[U]) -> bool { + *self == **other + } +} + // &[U] == Vec impl, U> PartialEq> for &[U] { fn eq(&self, other: &Vec) -> bool { - other == self + *other == **self + } +} + +// Vec == &mut [U] +impl, U> PartialEq<&mut [U]> for Vec { + fn eq(&self, other: &&mut [U]) -> bool { + *self == **other + } +} + +// &mut [U] == Vec +impl, U> PartialEq> for &mut [U] { + fn eq(&self, other: &Vec) -> bool { + *other == **self } } // Vec == [U; N] impl, U, const N: usize> PartialEq<[U; N]> for Vec { fn eq(&self, other: &[U; N]) -> bool { - *self == &other[..] + *self == other[..] } } // [U; N] == Vec impl, U, const N: usize> PartialEq> for [U; N] { fn eq(&self, other: &Vec) -> bool { - other == self + *other == self[..] + } +} + +// Vec == &[U; N] +impl, U, const N: usize> PartialEq<&[U; N]> for Vec { + fn eq(&self, other: &&[U; N]) -> bool { + *self == other[..] + } +} + +// &[U; N] == Vec +impl, U, const N: usize> PartialEq> for &[U; N] { + fn eq(&self, other: &Vec) -> bool { + *other == self[..] + } +} + +// Vec == &mut [U; N] +impl, U, const N: usize> PartialEq<&mut [U; N]> for Vec { + fn eq(&self, other: &&mut [U; N]) -> bool { + *self == other[..] + } +} + +// &mut [U; N] == Vec +impl, U, const N: usize> PartialEq> for &mut [U; N] { + fn eq(&self, other: &Vec) -> bool { + *other == self[..] } } diff --git a/src/lib.rs b/src/lib.rs index f73007a..15220d7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -511,7 +511,7 @@ impl Vec { } /// Removes the element at the specified index, shifting other elements over to fill the gap. - pub fn remove(&mut self, index: usize) -> Option> where T: std::fmt::Debug { + pub fn remove(&mut self, index: usize) -> Option> { if index >= self.len { return None }