diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index 961fca0f02b9a..ed578f3f515b6 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -729,6 +729,15 @@ impl FromIterator for String { } } +#[experimental = "waiting on FromIterator stabilization"] +impl<'a> FromIterator<&'a str> for String { + fn from_iter>(iterator: I) -> String { + let mut buf = String::new(); + buf.extend(iterator); + buf + } +} + #[experimental = "waiting on Extend stabilization"] impl Extend for String { fn extend>(&mut self, mut iterator: I) { @@ -740,6 +749,18 @@ impl Extend for String { } } +#[experimental = "waiting on Extend stabilization"] +impl<'a> Extend<&'a str> for String { + fn extend>(&mut self, mut iterator: I) { + // A guess that at least one byte per iterator element will be needed. + let (lower_bound, _) = iterator.size_hint(); + self.reserve(lower_bound); + for s in iterator { + self.push_str(s) + } + } +} + impl PartialEq for String { #[inline] fn eq(&self, other: &String) -> bool { PartialEq::eq(&**self, &**other) }