From 65df4480b57b67c250525326a6c659af23a30a62 Mon Sep 17 00:00:00 2001 From: Eh2406 Date: Fri, 21 Apr 2017 13:25:48 -0400 Subject: [PATCH 1/2] FromIterator and Extend Cow for String --- src/libcollections/string.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index 8d6cf30511260..675d701df7398 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -1538,6 +1538,15 @@ impl FromIterator for String { } } +#[stable(feature = "herd_cows", since = "1.9.0")] +impl<'a> FromIterator> for String { + fn from_iter>>(iter: I) -> String { + let mut buf = String::new(); + buf.extend(iter); + buf + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl Extend for String { fn extend>(&mut self, iter: I) { @@ -1575,6 +1584,15 @@ impl Extend for String { } } +#[stable(feature = "herd_cows", since = "1.9.0")] +impl<'a> Extend> for String { + fn extend>>(&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", From 4d8d386255031c70f2ee61cbe6b1149d7ed5b90a Mon Sep 17 00:00:00 2001 From: Eh2406 Date: Mon, 24 Apr 2017 12:32:10 -0400 Subject: [PATCH 2/2] FromIterator and Extend Borrow for String --- src/libcollections/string.rs | 67 +++++++++--------------------------- 1 file changed, 16 insertions(+), 51 deletions(-) diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index 675d701df7398..aebf382a3de0d 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -56,6 +56,7 @@ #![stable(feature = "rust1", since = "1.0.0")] +use core::borrow::Borrow; use core::fmt; use core::hash; use core::iter::{FromIterator, FusedIterator}; @@ -1502,6 +1503,15 @@ impl Clone for String { } } +#[stable(feature = "herd_cows", since = "1.9.0")] +impl> FromIterator for String { + default fn from_iter>(iter: I) -> String { + let mut buf = String::new(); + buf.extend(iter); + buf + } + } + #[stable(feature = "rust1", since = "1.0.0")] impl FromIterator for String { fn from_iter>(iter: I) -> String { @@ -1520,31 +1530,13 @@ impl<'a> FromIterator<&'a char> for String { } } -#[stable(feature = "rust1", since = "1.0.0")] -impl<'a> FromIterator<&'a str> for String { - fn from_iter>(iter: I) -> String { - let mut buf = String::new(); - buf.extend(iter); - buf - } -} - -#[stable(feature = "extend_string", since = "1.4.0")] -impl FromIterator for String { - fn from_iter>(iter: I) -> String { - let mut buf = String::new(); - buf.extend(iter); - buf - } -} - #[stable(feature = "herd_cows", since = "1.9.0")] -impl<'a> FromIterator> for String { - fn from_iter>>(iter: I) -> String { - let mut buf = String::new(); - buf.extend(iter); - buf - } +impl> Extend for String { + default fn extend>(&mut self, iter: I) { + for s in iter { + self.push_str(s.borrow()) + } + } } #[stable(feature = "rust1", since = "1.0.0")] @@ -1566,33 +1558,6 @@ impl<'a> Extend<&'a char> for String { } } -#[stable(feature = "rust1", since = "1.0.0")] -impl<'a> Extend<&'a str> for String { - fn extend>(&mut self, iter: I) { - for s in iter { - self.push_str(s) - } - } -} - -#[stable(feature = "extend_string", since = "1.4.0")] -impl Extend for String { - fn extend>(&mut self, iter: I) { - for s in iter { - self.push_str(&s) - } - } -} - -#[stable(feature = "herd_cows", since = "1.9.0")] -impl<'a> Extend> for String { - fn extend>>(&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",