about summary refs log tree commit diff
path: root/library/alloc/src/string.rs
diff options
context:
space:
mode:
authorMatthew Zeitlin <37011898+mzeitlin11@users.noreply.github.com>2025-02-08 16:51:04 -0500
committerMatthew Zeitlin <37011898+mzeitlin11@users.noreply.github.com>2025-02-08 16:51:04 -0500
commitd566b5db9bacd68c696d456a6d18569a50e7cb58 (patch)
treed7961df8a9670149969e41eacff53b65eb19d12e /library/alloc/src/string.rs
parent73bf7947e9ab731bf2764db219cd9cda216a3aed (diff)
downloadrust-d566b5db9bacd68c696d456a6d18569a50e7cb58.tar.gz
rust-d566b5db9bacd68c696d456a6d18569a50e7cb58.zip
Implement Extend<AsciiChar> for String
Diffstat (limited to 'library/alloc/src/string.rs')
-rw-r--r--library/alloc/src/string.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/library/alloc/src/string.rs b/library/alloc/src/string.rs
index b29f740ef0f..154da691078 100644
--- a/library/alloc/src/string.rs
+++ b/library/alloc/src/string.rs
@@ -2442,6 +2442,32 @@ impl<'a> Extend<Cow<'a, str>> for String {
     }
 }
 
+#[cfg(not(no_global_oom_handling))]
+#[unstable(feature = "ascii_char", issue = "110998")]
+impl Extend<core::ascii::Char> for String {
+    fn extend<I: IntoIterator<Item = core::ascii::Char>>(&mut self, iter: I) {
+        self.vec.extend(iter.into_iter().map(|c| c.to_u8()));
+    }
+
+    #[inline]
+    fn extend_one(&mut self, c: core::ascii::Char) {
+        self.vec.push(c.to_u8());
+    }
+}
+
+#[cfg(not(no_global_oom_handling))]
+#[unstable(feature = "ascii_char", issue = "110998")]
+impl<'a> Extend<&'a core::ascii::Char> for String {
+    fn extend<I: IntoIterator<Item = &'a core::ascii::Char>>(&mut self, iter: I) {
+        self.extend(iter.into_iter().cloned());
+    }
+
+    #[inline]
+    fn extend_one(&mut self, c: &'a core::ascii::Char) {
+        self.vec.push(c.to_u8());
+    }
+}
+
 /// A convenience impl that delegates to the impl for `&str`.
 ///
 /// # Examples