]> git.lizzy.rs Git - rust.git/commitdiff
libcollections: add commutative version of `Vec`/`String` addition
authorJorge Aparicio <japaricious@gmail.com>
Wed, 3 Dec 2014 07:22:41 +0000 (02:22 -0500)
committerJorge Aparicio <japaricious@gmail.com>
Sun, 14 Dec 2014 01:16:34 +0000 (20:16 -0500)
src/libcollections/string.rs
src/libcollections/vec.rs

index 0e3d2f02ae9c84c663c298ee0aaa5bb54e91e0fc..f3a9e7b1867585b78f46bd9b2d5203a46a59057f 100644 (file)
@@ -874,6 +874,14 @@ fn add(mut self, other: &str) -> String {
     }
 }
 
+#[cfg(not(stage0))]  // NOTE(stage0): Remove cfg after a snapshot
+impl<'a> Add<String, String> for &'a str {
+    fn add(self, mut other: String) -> String {
+        other.push_str(self);
+        other
+    }
+}
+
 impl ops::Slice<uint, str> for String {
     #[inline]
     fn as_slice_<'a>(&'a self) -> &'a str {
index 56cfa19e887ad8861f82cbe9da8c66c007a51ebb..275825da3b55ffb67f5393650da6995de49937d9 100644 (file)
@@ -1295,6 +1295,15 @@ fn add(mut self, rhs: &[T]) -> Vec<T> {
     }
 }
 
+#[cfg(not(stage0))]  // NOTE(stage0): Remove impl after a snapshot
+impl<'a, T: Clone> Add<Vec<T>, Vec<T>> for &'a [T] {
+    #[inline]
+    fn add(self, mut rhs: Vec<T>) -> Vec<T> {
+        rhs.push_all(self);
+        rhs
+    }
+}
+
 #[unsafe_destructor]
 impl<T> Drop for Vec<T> {
     fn drop(&mut self) {