Skip to content

Commit 949b55e

Browse files
author
Jorge Aparicio
committed
libcollections: add commutative version of Vec/String addition
1 parent f4abb12 commit 949b55e

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/libcollections/string.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,14 @@ impl<'a> Add<&'a str, String> for String {
874874
}
875875
}
876876

877+
#[cfg(not(stage0))] // NOTE(stage0): Remove cfg after a snapshot
878+
impl<'a> Add<String, String> for &'a str {
879+
fn add(self, mut other: String) -> String {
880+
other.push_str(self);
881+
other
882+
}
883+
}
884+
877885
impl ops::Slice<uint, str> for String {
878886
#[inline]
879887
fn as_slice_<'a>(&'a self) -> &'a str {

src/libcollections/vec.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,6 +1295,15 @@ impl<'a, T: Clone> Add<&'a [T], Vec<T>> for Vec<T> {
12951295
}
12961296
}
12971297

1298+
#[cfg(not(stage0))] // NOTE(stage0): Remove impl after a snapshot
1299+
impl<'a, T: Clone> Add<Vec<T>, Vec<T>> for &'a [T] {
1300+
#[inline]
1301+
fn add(self, mut rhs: Vec<T>) -> Vec<T> {
1302+
rhs.push_all(self);
1303+
rhs
1304+
}
1305+
}
1306+
12981307
#[unsafe_destructor]
12991308
impl<T> Drop for Vec<T> {
13001309
fn drop(&mut self) {

0 commit comments

Comments
 (0)