diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index 8d6cf30511260..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,22 +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> 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")] @@ -1557,24 +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) - } - } -} - /// A convenience impl that delegates to the impl for `&str` #[unstable(feature = "pattern", reason = "API not fully fleshed out and ready to be stabilized",