Skip to content

Commit

Permalink
Implemented Extend<String> and FromIterator<String> for String.
Browse files Browse the repository at this point in the history
  • Loading branch information
withoutboats committed Aug 27, 2015
1 parent 0d5142f commit 8af543a
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions src/libcollections/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -768,18 +768,27 @@ impl fmt::Display for FromUtf16Error {

#[stable(feature = "rust1", since = "1.0.0")]
impl FromIterator<char> for String {
fn from_iter<I: IntoIterator<Item=char>>(iter: I) -> String {
fn from_iter<I: IntoIterator<Item=char>>(iterable: I) -> String {
let mut buf = String::new();
buf.extend(iter);
buf.extend(iterable);
buf
}
}

#[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 {
fn from_iter<I: IntoIterator<Item=&'a str>>(iterable: I) -> String {
let mut buf = String::new();
buf.extend(iter);
buf.extend(iterable);
buf
}
}

#[stable(feature = "extend_string", since = "1.4.0")]
impl FromIterator<String> for String {
fn from_iter<I: IntoIterator<Item=String>>(iterable: I) -> String {
let mut buf = String::new();
buf.extend(iterable);
buf
}
}
Expand All @@ -798,8 +807,8 @@ impl Extend<char> for String {

#[stable(feature = "extend_ref", since = "1.2.0")]
impl<'a> Extend<&'a char> for String {
fn extend<I: IntoIterator<Item=&'a char>>(&mut self, iter: I) {
self.extend(iter.into_iter().cloned());
fn extend<I: IntoIterator<Item=&'a char>>(&mut self, iterable: I) {
self.extend(iterable.into_iter().cloned());
}
}

Expand All @@ -812,6 +821,15 @@ impl<'a> Extend<&'a str> for String {
}
}

#[stable(feature = "extend_string", since = "1.4.0")]
impl Extend<String> for String {
fn extend<I: IntoIterator<Item=String>>(&mut self, iterable: I) {
for s in iterable {
self.push_str(&s)
}
}
}

/// A convenience impl that delegates to the impl for `&str`
impl<'a, 'b> Pattern<'a> for &'b String {
type Searcher = <&'b str as Pattern<'a>>::Searcher;
Expand Down

0 comments on commit 8af543a

Please sign in to comment.