how much PartialEq
would you like? yes
This commit is contained in:
parent
e34e33e5af
commit
dfaf41808f
70
src/impls.rs
70
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};
|
use crate::{Vec, Extra};
|
||||||
|
|
||||||
|
@ -30,9 +30,9 @@ impl<T: ?Sized + PartialEq<U>, U: ?Sized> PartialEq<Vec<U>> for Vec<T> {
|
||||||
|
|
||||||
impl<T: ?Sized + Eq> Eq for Vec<T> {}
|
impl<T: ?Sized + Eq> Eq for Vec<T> {}
|
||||||
|
|
||||||
// Vec<T> == &[U]
|
// Vec<T> == [U]
|
||||||
impl<T: PartialEq<U>, U> PartialEq<&[U]> for Vec<T> {
|
impl<T: PartialEq<U>, U> PartialEq<[U]> for Vec<T> {
|
||||||
fn eq(&self, other: &&[U]) -> bool {
|
fn eq(&self, other: &[U]) -> bool {
|
||||||
if self.len != other.len() { return false }
|
if self.len != other.len() { return false }
|
||||||
for (el, el2) in self.iter().zip(other.iter()) {
|
for (el, el2) in self.iter().zip(other.iter()) {
|
||||||
if el != el2 { return false }
|
if el != el2 { return false }
|
||||||
|
@ -41,24 +41,80 @@ impl<T: PartialEq<U>, U> PartialEq<&[U]> for Vec<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// [U] == Vec<T>
|
||||||
|
impl<T: PartialEq<U>, U> PartialEq<Vec<T>> for [U] {
|
||||||
|
fn eq(&self, other: &Vec<T>) -> bool {
|
||||||
|
other == self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vec<T> == &[U]
|
||||||
|
impl<T: PartialEq<U>, U> PartialEq<&[U]> for Vec<T> {
|
||||||
|
fn eq(&self, other: &&[U]) -> bool {
|
||||||
|
*self == **other
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// &[U] == Vec<T>
|
// &[U] == Vec<T>
|
||||||
impl<T: PartialEq<U>, U> PartialEq<Vec<T>> for &[U] {
|
impl<T: PartialEq<U>, U> PartialEq<Vec<T>> for &[U] {
|
||||||
fn eq(&self, other: &Vec<T>) -> bool {
|
fn eq(&self, other: &Vec<T>) -> bool {
|
||||||
other == self
|
*other == **self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vec<T> == &mut [U]
|
||||||
|
impl<T: PartialEq<U>, U> PartialEq<&mut [U]> for Vec<T> {
|
||||||
|
fn eq(&self, other: &&mut [U]) -> bool {
|
||||||
|
*self == **other
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// &mut [U] == Vec<T>
|
||||||
|
impl<T: PartialEq<U>, U> PartialEq<Vec<T>> for &mut [U] {
|
||||||
|
fn eq(&self, other: &Vec<T>) -> bool {
|
||||||
|
*other == **self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vec<T> == [U; N]
|
// Vec<T> == [U; N]
|
||||||
impl<T: PartialEq<U>, U, const N: usize> PartialEq<[U; N]> for Vec<T> {
|
impl<T: PartialEq<U>, U, const N: usize> PartialEq<[U; N]> for Vec<T> {
|
||||||
fn eq(&self, other: &[U; N]) -> bool {
|
fn eq(&self, other: &[U; N]) -> bool {
|
||||||
*self == &other[..]
|
*self == other[..]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// [U; N] == Vec<T>
|
// [U; N] == Vec<T>
|
||||||
impl<T: PartialEq<U>, U, const N: usize> PartialEq<Vec<T>> for [U; N] {
|
impl<T: PartialEq<U>, U, const N: usize> PartialEq<Vec<T>> for [U; N] {
|
||||||
fn eq(&self, other: &Vec<T>) -> bool {
|
fn eq(&self, other: &Vec<T>) -> bool {
|
||||||
other == self
|
*other == self[..]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vec<T> == &[U; N]
|
||||||
|
impl<T: PartialEq<U>, U, const N: usize> PartialEq<&[U; N]> for Vec<T> {
|
||||||
|
fn eq(&self, other: &&[U; N]) -> bool {
|
||||||
|
*self == other[..]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// &[U; N] == Vec<T>
|
||||||
|
impl<T: PartialEq<U>, U, const N: usize> PartialEq<Vec<T>> for &[U; N] {
|
||||||
|
fn eq(&self, other: &Vec<T>) -> bool {
|
||||||
|
*other == self[..]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vec<T> == &mut [U; N]
|
||||||
|
impl<T: PartialEq<U>, U, const N: usize> PartialEq<&mut [U; N]> for Vec<T> {
|
||||||
|
fn eq(&self, other: &&mut [U; N]) -> bool {
|
||||||
|
*self == other[..]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// &mut [U; N] == Vec<T>
|
||||||
|
impl<T: PartialEq<U>, U, const N: usize> PartialEq<Vec<T>> for &mut [U; N] {
|
||||||
|
fn eq(&self, other: &Vec<T>) -> bool {
|
||||||
|
*other == self[..]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -511,7 +511,7 @@ impl<T: ?Sized> Vec<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Removes the element at the specified index, shifting other elements over to fill the gap.
|
/// Removes the element at the specified index, shifting other elements over to fill the gap.
|
||||||
pub fn remove(&mut self, index: usize) -> Option<Box<T>> where T: std::fmt::Debug {
|
pub fn remove(&mut self, index: usize) -> Option<Box<T>> {
|
||||||
if index >= self.len {
|
if index >= self.len {
|
||||||
return None
|
return None
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue