std: Bring back half of Add on String
This adds an implementation of Add for String where the rhs is <S: Str>. The other half of adding strings is where the lhs is <S: Str>, but coherence and the libcore separation currently prevent that.
This commit is contained in:
parent
05ca9f747d
commit
f7f95c8f5a
1 changed files with 17 additions and 0 deletions
|
@ -352,6 +352,14 @@ impl<'a, S: Str> Equiv<S> for String {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<S: Str> Add<S, String> for String {
|
||||||
|
fn add(&self, other: &S) -> String {
|
||||||
|
let mut s = self.to_string();
|
||||||
|
s.push_str(other.as_slice());
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::prelude::*;
|
use std::prelude::*;
|
||||||
|
@ -469,4 +477,13 @@ mod tests {
|
||||||
assert_eq!(s.len(), 0);
|
assert_eq!(s.len(), 0);
|
||||||
assert_eq!(s.as_slice(), "");
|
assert_eq!(s.as_slice(), "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_str_add() {
|
||||||
|
let a = String::from_str("12345");
|
||||||
|
let b = a + "2";
|
||||||
|
let b = b + String::from_str("2");
|
||||||
|
assert_eq!(b.len(), 7);
|
||||||
|
assert_eq!(b.as_slice(), "1234522");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue