Skip to content

Commit

Permalink
Implement RFC 839 for String
Browse files Browse the repository at this point in the history
  • Loading branch information
jooert committed Jun 3, 2015
1 parent 11de947 commit e3009d3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/libcollections/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,13 @@ impl Extend<char> for String {
}
}

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

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> Extend<&'a str> for String {
fn extend<I: IntoIterator<Item=&'a str>>(&mut self, iterable: I) {
Expand Down
8 changes: 8 additions & 0 deletions src/libcollectionstest/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,14 @@ fn test_drain() {
assert_eq!(t, "");
}

#[test]
fn test_extend_ref() {
let mut a = "foo".to_string();
a.extend(&['b', 'a', 'r']);

assert_eq!(&a, "foobar");
}

#[bench]
fn bench_with_capacity(b: &mut Bencher) {
b.iter(|| {
Expand Down

0 comments on commit e3009d3

Please sign in to comment.