]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #35064 - pthariensflame:feature/cow_str_from_iter, r=alexcrichton
authorbors <bors@rust-lang.org>
Mon, 8 Aug 2016 21:59:30 +0000 (14:59 -0700)
committerGitHub <noreply@github.com>
Mon, 8 Aug 2016 21:59:30 +0000 (14:59 -0700)
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

index 06952253ef3b09540017a1211dccd8e75b21bfe5..70b514afd035f1d17d446c0dbbee6f158b1eb950 100644 (file)
@@ -1874,6 +1874,27 @@ fn from(s: String) -> Cow<'a, str> {
     }
 }
 
+#[stable(feature = "cow_str_from_iter", since = "1.12.0")]
+impl<'a> 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> 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> 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> {