about summary refs log tree commit diff
path: root/src/libcollections/string.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/libcollections/string.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/libcollections/string.rs')
-rw-r--r--src/libcollections/string.rs45
1 files changed, 44 insertions, 1 deletions
diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs
index 38b67fbd744..180978b3d77 100644
--- a/src/libcollections/string.rs
+++ b/src/libcollections/string.rs
@@ -30,7 +30,7 @@ use str::{CharRange, CowString, FromStr, StrAllocating, Owned};
 use vec::{DerefVec, Vec, as_vec};
 
 /// A growable string stored as a UTF-8 encoded buffer.
-#[deriving(Clone, PartialEq, PartialOrd, Eq, Ord)]
+#[deriving(Clone, PartialOrd, Eq, Ord)]
 #[stable]
 pub struct String {
     vec: Vec<u8>,
@@ -738,6 +738,49 @@ impl Extend<char> for String {
     }
 }
 
+impl PartialEq for String {
+    #[inline]
+    fn eq(&self, other: &String) -> bool { PartialEq::eq(&**self, &**other) }
+    #[inline]
+    fn ne(&self, other: &String) -> bool { PartialEq::ne(&**self, &**other) }
+}
+
+macro_rules! impl_eq {
+    ($lhs:ty, $rhs: ty) => {
+        impl<'a> PartialEq<$rhs> for $lhs {
+            #[inline]
+            fn eq(&self, other: &$rhs) -> bool { PartialEq::eq(&**self, &**other) }
+            #[inline]
+            fn ne(&self, other: &$rhs) -> bool { PartialEq::ne(&**self, &**other) }
+        }
+
+        impl<'a> PartialEq<$lhs> for $rhs {
+            #[inline]
+            fn eq(&self, other: &$lhs) -> bool { PartialEq::eq(&**self, &**other) }
+            #[inline]
+            fn ne(&self, other: &$lhs) -> bool { PartialEq::ne(&**self, &**other) }
+        }
+
+    }
+}
+
+impl_eq!(String, &'a str)
+impl_eq!(CowString<'a>, String)
+
+impl<'a, 'b> PartialEq<&'b str> for CowString<'a> {
+    #[inline]
+    fn eq(&self, other: &&'b str) -> bool { PartialEq::eq(&**self, &**other) }
+    #[inline]
+    fn ne(&self, other: &&'b str) -> bool { PartialEq::ne(&**self, &**other) }
+}
+
+impl<'a, 'b> PartialEq<CowString<'a>> for &'b str {
+    #[inline]
+    fn eq(&self, other: &CowString<'a>) -> bool { PartialEq::eq(&**self, &**other) }
+    #[inline]
+    fn ne(&self, other: &CowString<'a>) -> bool { PartialEq::ne(&**self, &**other) }
+}
+
 #[experimental = "waiting on Str stabilization"]
 impl Str for String {
     #[inline]