Overload the == operator
- String == &str == CowString - Vec == &[T] == &mut [T] == [T, ..N] == CowVec - InternedString == &str
This commit is contained in:
@@ -18,6 +18,7 @@ use clone::Clone;
|
||||
use cmp::{PartialEq, Eq, PartialOrd, Ord, Ordering};
|
||||
use fmt;
|
||||
use kinds::Copy;
|
||||
use ops::Deref;
|
||||
use option::Option;
|
||||
|
||||
// macro for implementing n-ary tuple functions and operations
|
||||
@@ -39,17 +40,37 @@ macro_rules! array_impls {
|
||||
}
|
||||
|
||||
#[unstable = "waiting for PartialEq to stabilize"]
|
||||
impl<T:PartialEq> PartialEq for [T, ..$N] {
|
||||
impl<A, B> PartialEq<[B, ..$N]> for [A, ..$N] where A: PartialEq<B> {
|
||||
#[inline]
|
||||
fn eq(&self, other: &[T, ..$N]) -> bool {
|
||||
fn eq(&self, other: &[B, ..$N]) -> bool {
|
||||
self[] == other[]
|
||||
}
|
||||
#[inline]
|
||||
fn ne(&self, other: &[T, ..$N]) -> bool {
|
||||
fn ne(&self, other: &[B, ..$N]) -> bool {
|
||||
self[] != other[]
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, A, B, Rhs> PartialEq<Rhs> for [A, ..$N] where
|
||||
A: PartialEq<B>,
|
||||
Rhs: Deref<[B]>,
|
||||
{
|
||||
#[inline(always)]
|
||||
fn eq(&self, other: &Rhs) -> bool { PartialEq::eq(self[], &**other) }
|
||||
#[inline(always)]
|
||||
fn ne(&self, other: &Rhs) -> bool { PartialEq::ne(self[], &**other) }
|
||||
}
|
||||
|
||||
impl<'a, A, B, Lhs> PartialEq<[B, ..$N]> for Lhs where
|
||||
A: PartialEq<B>,
|
||||
Lhs: Deref<[A]>
|
||||
{
|
||||
#[inline(always)]
|
||||
fn eq(&self, other: &[B, ..$N]) -> bool { PartialEq::eq(&**self, other[]) }
|
||||
#[inline(always)]
|
||||
fn ne(&self, other: &[B, ..$N]) -> bool { PartialEq::ne(&**self, other[]) }
|
||||
}
|
||||
|
||||
#[unstable = "waiting for Eq to stabilize"]
|
||||
impl<T:Eq> Eq for [T, ..$N] { }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user