diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2016-07-21 11:27:00 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-07-21 11:27:00 +0200 |
| commit | 4817c5e53d18897d9c851dffc293d6ac3d7fecdf (patch) | |
| tree | beade6b2dbb0028e30819e340dddc6202d7dd478 /src | |
| parent | 9ba1792aac8b01a313c87611a2525a87a6606bc3 (diff) | |
| parent | 9b8130666de569d6d27332d42df43859a57b3e72 (diff) | |
| download | rust-4817c5e53d18897d9c851dffc293d6ac3d7fecdf.tar.gz rust-4817c5e53d18897d9c851dffc293d6ac3d7fecdf.zip | |
Rollup merge of #34890 - oconnor663:addassign, r=brson
implement AddAssign for String Currently `String` implements `Add` but not `AddAssign`. This PR fills in that gap. I played around with having `AddAssign` (and `Add` and `push_str`) take `AsRef<str>` instead of `&str`, but it looks like that breaks arguments that implement `Deref<Target=str>` and not `AsRef<str>`. Comments in [`libcore/convert.rs`](https://github.com/rust-lang/rust/blob/master/src/libcore/convert.rs#L207-L213) make it sound like we could fix this with a blanket impl eventually. Does anyone know what's blocking that?
Diffstat (limited to 'src')
| -rw-r--r-- | src/libcollections/string.rs | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index 8ba5c6ffbf2..a2d1f09b6a5 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -59,7 +59,7 @@ use core::fmt; use core::hash; use core::iter::FromIterator; use core::mem; -use core::ops::{self, Add, Index, IndexMut}; +use core::ops::{self, Add, AddAssign, Index, IndexMut}; use core::ptr; use core::str::pattern::Pattern; use rustc_unicode::char::{decode_utf16, REPLACEMENT_CHARACTER}; @@ -1565,6 +1565,14 @@ impl<'a> Add<&'a str> for String { } } +#[stable(feature = "stringaddassign", since = "1.12.0")] +impl<'a> AddAssign<&'a str> for String { + #[inline] + fn add_assign(&mut self, other: &str) { + self.push_str(other); + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl ops::Index<ops::Range<usize>> for String { type Output = str; |
