diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-05-27 21:34:00 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-06-24 17:17:09 -0700 |
| commit | f7f95c8f5a6294f161800dbb65a0423bb5248f34 (patch) | |
| tree | f99883567070e1eadc6316d4ac96484530553223 /src | |
| parent | 05ca9f747d62c9385cc142daa3c24a32d32a3f16 (diff) | |
| download | rust-f7f95c8f5a6294f161800dbb65a0423bb5248f34.tar.gz rust-f7f95c8f5a6294f161800dbb65a0423bb5248f34.zip | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/libcollections/string.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index 76f53c9b257..6d1fc43a4f1 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -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)] mod tests { use std::prelude::*; @@ -469,4 +477,13 @@ mod tests { assert_eq!(s.len(), 0); 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"); + } } |
