Skip to content

Commit 5311daa

Browse files
authored
Rollup merge of #72688 - djugei:master, r=Amanieu
added .collect() into String from Box<str> I have not created an rfc, because i felt like this is a very minor change. i have just set a random feature name and rust version as stability attribute, i expect to have to change that, i just don't know what the policy on that is. all guides i could find focused on contributing to the compiler, not contributing to the standard library. drawbacks: more code in the standard library, could be replaced with specialization: base-implementation for AsRef\<str> and specialization for String and Cow. i can write that code if ppl want it. advantages: using "real strings" i.e. Box\<str> is as ergonomic as string slices (&str) and string buffers (String) with iterators.
2 parents 2753fab + b4337ab commit 5311daa

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/liballoc/string.rs

+16
Original file line numberDiff line numberDiff line change
@@ -1774,6 +1774,15 @@ impl FromIterator<String> for String {
17741774
}
17751775
}
17761776

1777+
#[stable(feature = "box_str2", since = "1.45.0")]
1778+
impl FromIterator<Box<str>> for String {
1779+
fn from_iter<I: IntoIterator<Item = Box<str>>>(iter: I) -> String {
1780+
let mut buf = String::new();
1781+
buf.extend(iter);
1782+
buf
1783+
}
1784+
}
1785+
17771786
#[stable(feature = "herd_cows", since = "1.19.0")]
17781787
impl<'a> FromIterator<Cow<'a, str>> for String {
17791788
fn from_iter<I: IntoIterator<Item = Cow<'a, str>>>(iter: I) -> String {
@@ -1842,6 +1851,13 @@ impl<'a> Extend<&'a str> for String {
18421851
}
18431852
}
18441853

1854+
#[stable(feature = "box_str2", since = "1.45.0")]
1855+
impl Extend<Box<str>> for String {
1856+
fn extend<I: IntoIterator<Item = Box<str>>>(&mut self, iter: I) {
1857+
iter.into_iter().for_each(move |s| self.push_str(&s));
1858+
}
1859+
}
1860+
18451861
#[stable(feature = "extend_string", since = "1.4.0")]
18461862
impl Extend<String> for String {
18471863
fn extend<I: IntoIterator<Item = String>>(&mut self, iter: I) {

0 commit comments

Comments
 (0)