diff options
| author | Corey Farwell <coreyf@rwell.org> | 2017-04-29 23:44:27 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-04-29 23:44:27 -0400 |
| commit | ab99c9beb54e6853f07f37538aefd9a396f6945f (patch) | |
| tree | 0b572092315123df3a47a06ae5560c8e94e06f0d | |
| parent | afa1240e57330d85a372db4e28cd8bc8fa528ccb (diff) | |
| parent | 0e2571b4ad967b1aa663a61faff73b6217e5a4a8 (diff) | |
| download | rust-ab99c9beb54e6853f07f37538aefd9a396f6945f.tar.gz rust-ab99c9beb54e6853f07f37538aefd9a396f6945f.zip | |
Rollup merge of #41449 - Eh2406:master, r=aturon
FromIterator and Extend Cow for String This is a quick draft to start working on [#41351](https://github.com/rust-lang/rust/issues/41351). I don't think I got the stable attributes correct, but it is good enuf to start a conversation.
| -rw-r--r-- | src/libcollections/string.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index aa9628c535a..31ab04e9f3b 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -1604,6 +1604,15 @@ impl FromIterator<String> for String { } } +#[stable(feature = "herd_cows", since = "1.19.0")] +impl<'a> FromIterator<Cow<'a, str>> for String { + fn from_iter<I: IntoIterator<Item = Cow<'a, str>>>(iter: I) -> String { + let mut buf = String::new(); + buf.extend(iter); + buf + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl Extend<char> for String { fn extend<I: IntoIterator<Item = char>>(&mut self, iter: I) { @@ -1641,6 +1650,15 @@ impl Extend<String> for String { } } +#[stable(feature = "herd_cows", since = "1.19.0")] +impl<'a> Extend<Cow<'a, str>> for String { + fn extend<I: IntoIterator<Item = Cow<'a, str>>>(&mut self, iter: I) { + for s in iter { + self.push_str(&s) + } + } +} + /// A convenience impl that delegates to the impl for `&str` #[unstable(feature = "pattern", reason = "API not fully fleshed out and ready to be stabilized", |
