]> git.lizzy.rs Git - rust.git/commitdiff
FromIterator and Extend Cow for String
authorEh2406 <YeomanYaacov@gmail.com>
Fri, 21 Apr 2017 17:25:48 +0000 (13:25 -0400)
committerEh2406 <YeomanYaacov@gmail.com>
Sat, 29 Apr 2017 02:30:12 +0000 (22:30 -0400)
src/libcollections/string.rs

index aa9628c535a997fb18939a2a7f66a85c61f10acb..31ab04e9f3b74f049098a2e19aed23ec67f35df2 100644 (file)
@@ -1604,6 +1604,15 @@ fn from_iter<I: IntoIterator<Item = String>>(iter: I) -> String {
     }
 }
 
+#[stable(feature = "herd_cows", since = "1.19.0")]
+impl<'a> FromIterator<Cow<'a, str>> for String {
+    fn from_iter<I: IntoIterator<Item = Cow<'a, str>>>(iter: I) -> String {
+        let mut buf = String::new();
+        buf.extend(iter);
+        buf
+    }
+}
+
 #[stable(feature = "rust1", since = "1.0.0")]
 impl Extend<char> for String {
     fn extend<I: IntoIterator<Item = char>>(&mut self, iter: I) {
@@ -1641,6 +1650,15 @@ fn extend<I: IntoIterator<Item = String>>(&mut self, iter: I) {
     }
 }
 
+#[stable(feature = "herd_cows", since = "1.19.0")]
+impl<'a> Extend<Cow<'a, str>> for String {
+    fn extend<I: IntoIterator<Item = Cow<'a, str>>>(&mut self, iter: I) {
+        for s in iter {
+            self.push_str(&s)
+        }
+    }
+}
+
 /// A convenience impl that delegates to the impl for `&str`
 #[unstable(feature = "pattern",
            reason = "API not fully fleshed out and ready to be stabilized",