Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gen herd cows #41506

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 17 additions & 34 deletions src/libcollections/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -1502,6 +1503,15 @@ impl Clone for String {
}
}

#[stable(feature = "herd_cows", since = "1.9.0")]
impl<T: Borrow<str>> FromIterator<T> for String {
default fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> String {
let mut buf = String::new();
buf.extend(iter);
buf
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl FromIterator<char> for String {
fn from_iter<I: IntoIterator<Item = char>>(iter: I) -> String {
Expand All @@ -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<I: IntoIterator<Item = &'a str>>(iter: I) -> String {
let mut buf = String::new();
buf.extend(iter);
buf
}
}

#[stable(feature = "extend_string", since = "1.4.0")]
impl FromIterator<String> for String {
fn from_iter<I: IntoIterator<Item = String>>(iter: I) -> String {
let mut buf = String::new();
buf.extend(iter);
buf
}
#[stable(feature = "herd_cows", since = "1.9.0")]
impl<T: Borrow<str>> Extend<T> for String {
default fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I) {
for s in iter {
self.push_str(s.borrow())
}
}
}

#[stable(feature = "rust1", since = "1.0.0")]
Expand All @@ -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<I: IntoIterator<Item = &'a str>>(&mut self, iter: I) {
for s in iter {
self.push_str(s)
}
}
}

#[stable(feature = "extend_string", since = "1.4.0")]
impl Extend<String> for String {
fn extend<I: IntoIterator<Item = String>>(&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",
Expand Down