From 0fabe17e19425e1e30ca3d2a5e74cb3714039d26 Mon Sep 17 00:00:00 2001 From: Alexander Altman <alexanderaltman@me.com> Date: Tue, 26 Jul 2016 21:16:46 -0700 Subject: [PATCH] Add `FromIterator` implementations for `Cow<str>` This seems like an oversight, since the corresponding implementation for `Cow<[T]> where T: Clone` exists. --- src/libcollections/string.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index f91d8a5f4e1e8..24d6e9f537e57 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -1874,6 +1874,27 @@ impl<'a> From<String> for Cow<'a, str> { } } +#[stable(feature = "cow_str_from_iter", since = "1.12.0")] +impl<'a, T> FromIterator<char> for Cow<'a, str> { + fn from_iter<I: IntoIterator<Item = char>>(it: I) -> Cow<'a, str> { + Cow::Owned(FromIterator::from_iter(it)) + } +} + +#[stable(feature = "cow_str_from_iter", since = "1.12.0")] +impl<'a, 'b, T> FromIterator<&'b str> for Cow<'a, str> { + fn from_iter<I: IntoIterator<Item = &'b str>>(it: I) -> Cow<'a, str> { + Cow::Owned(FromIterator::from_iter(it)) + } +} + +#[stable(feature = "cow_str_from_iter", since = "1.12.0")] +impl<'a, T> FromIterator<String> for Cow<'a, str> { + fn from_iter<I: IntoIterator<Item = String>>(it: I) -> Cow<'a, str> { + Cow::Owned(FromIterator::from_iter(it)) + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl Into<Vec<u8>> for String { fn into(self) -> Vec<u8> {