about summary refs log tree commit diff
path: root/src/libcore/array.rs
diff options
context:
space:
mode:
authorJorge Aparicio <japaricious@gmail.com>2014-11-21 00:14:05 -0500
committerJorge Aparicio <japaricious@gmail.com>2014-12-03 10:41:42 -0500
commit2840d58dab0144c5589b60322c4f681bd8052aba (patch)
tree0c48a16b8c12222544acc8f2e7289381bd5af631 /src/libcore/array.rs
parent2578de9d6090210d9e94fd013190f387c8a88048 (diff)
downloadrust-2840d58dab0144c5589b60322c4f681bd8052aba.tar.gz
rust-2840d58dab0144c5589b60322c4f681bd8052aba.zip
Overload the `==` operator
- String == &str == CowString
- Vec ==  &[T] ==  &mut [T] == [T, ..N] == CowVec
- InternedString == &str
Diffstat (limited to 'src/libcore/array.rs')
-rw-r--r--src/libcore/array.rs27
1 files changed, 24 insertions, 3 deletions
diff --git a/src/libcore/array.rs b/src/libcore/array.rs
index 60765e82cb4..ffaf35414ea 100644
--- a/src/libcore/array.rs
+++ b/src/libcore/array.rs
@@ -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] { }