about summary refs log tree commit diff
path: root/library/alloc/src/string.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-05-19 02:13:06 +0000
committerbors <bors@rust-lang.org>2024-05-19 02:13:06 +0000
commitbfa3635df920454cdf03f6d268dfaac769375df3 (patch)
treefc8538014f461a0fb508c554738b513d734db18c /library/alloc/src/string.rs
parent7690f29bdb6460ab525a8e8919420a4675a93386 (diff)
parentc92c22826015168581f82e8b0f870a8cef9209b9 (diff)
downloadrust-bfa3635df920454cdf03f6d268dfaac769375df3.tar.gz
rust-bfa3635df920454cdf03f6d268dfaac769375df3.zip
Auto merge of #99969 - calebsander:feature/collect-box-str, r=dtolnay
alloc: implement FromIterator for Box<str>

`Box<[T]>` implements `FromIterator<T>` using `Vec<T>` + `into_boxed_slice()`.
Add analogous `FromIterator` implementations for `Box<str>`
matching the current implementations for `String`.
Remove the `Global` allocator requirement for `FromIterator<Box<str>>` too.

ACP: https://github.com/rust-lang/libs-team/issues/196
Diffstat (limited to 'library/alloc/src/string.rs')
-rw-r--r--library/alloc/src/string.rs10
1 files changed, 6 insertions, 4 deletions
diff --git a/library/alloc/src/string.rs b/library/alloc/src/string.rs
index 335a1a8ffb3..36078da7c35 100644
--- a/library/alloc/src/string.rs
+++ b/library/alloc/src/string.rs
@@ -60,6 +60,8 @@ use core::slice;
 use core::str::pattern::Pattern;
 
 #[cfg(not(no_global_oom_handling))]
+use crate::alloc::Allocator;
+#[cfg(not(no_global_oom_handling))]
 use crate::borrow::{Cow, ToOwned};
 use crate::boxed::Box;
 use crate::collections::TryReserveError;
@@ -2157,8 +2159,8 @@ impl FromIterator<String> for String {
 
 #[cfg(not(no_global_oom_handling))]
 #[stable(feature = "box_str2", since = "1.45.0")]
-impl FromIterator<Box<str>> for String {
-    fn from_iter<I: IntoIterator<Item = Box<str>>>(iter: I) -> String {
+impl<A: Allocator> FromIterator<Box<str, A>> for String {
+    fn from_iter<I: IntoIterator<Item = Box<str, A>>>(iter: I) -> String {
         let mut buf = String::new();
         buf.extend(iter);
         buf
@@ -2239,8 +2241,8 @@ impl<'a> Extend<&'a str> for String {
 
 #[cfg(not(no_global_oom_handling))]
 #[stable(feature = "box_str2", since = "1.45.0")]
-impl Extend<Box<str>> for String {
-    fn extend<I: IntoIterator<Item = Box<str>>>(&mut self, iter: I) {
+impl<A: Allocator> Extend<Box<str, A>> for String {
+    fn extend<I: IntoIterator<Item = Box<str, A>>>(&mut self, iter: I) {
         iter.into_iter().for_each(move |s| self.push_str(&s));
     }
 }