Skip to content

Commit 09a15ef

Browse files
committed
Implementing Extend for String in terms of for_each now that that's been added
1 parent d6f16b6 commit 09a15ef

File tree

1 file changed

+9
-19
lines changed

1 file changed

+9
-19
lines changed

src/string/extend.rs

+9-19
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,25 @@ impl Extend<char> for String {
1010
stream: S,
1111
) -> Pin<Box<dyn Future<Output = ()> + 'a>> {
1212
let stream = stream.into_stream();
13-
//TODO: Add this back in when size_hint is added to stream
13+
//TODO: Add this back in when size_hint is added to Stream/StreamExt
1414
// let (lower_bound, _) = stream.size_hint();
1515
// self.reserve(lower_bound);
1616

17-
//TODO: This can just be: stream.for_each(move |c| self.push(c))
18-
Box::pin(stream.fold((), move |(), c| self.push(c)))
17+
Box::pin(stream.for_each(move |c| self.push(c)))
1918
}
2019
}
2120

2221
impl<'b> Extend<&'b char> for String {
2322
fn stream_extend<'a, S: IntoStream<Item = &'b char> + 'a>(
2423
&'a mut self,
25-
stream: S,
24+
//TODO: Remove the underscore when uncommenting the body of this impl
25+
_stream: S,
2626
) -> Pin<Box<dyn Future<Output = ()> + 'a>>
2727
where
2828
'b: 'a,
2929
{
30-
//TODO: Box::pin(stream.into_stream().copied())
30+
//TODO: This can be uncommented when `copied` is added to Stream/StreamExt
31+
//Box::pin(stream.into_stream().copied())
3132
unimplemented!()
3233
}
3334
}
@@ -40,8 +41,7 @@ impl<'b> Extend<&'b str> for String {
4041
where
4142
'b: 'a,
4243
{
43-
//TODO: This can just be: stream.into_stream().for_each(move |s| self.push_str(s))
44-
Box::pin(stream.into_stream().fold((), move |(), s| self.push_str(s)))
44+
Box::pin(stream.into_stream().for_each(move |s| self.push_str(s)))
4545
}
4646
}
4747

@@ -50,12 +50,7 @@ impl Extend<String> for String {
5050
&'a mut self,
5151
stream: S,
5252
) -> Pin<Box<dyn Future<Output = ()> + 'a>> {
53-
//TODO: This can just be: stream.into_stream().for_each(move |s| self.push_str(&s))
54-
Box::pin(
55-
stream
56-
.into_stream()
57-
.fold((), move |(), s| self.push_str(&s)),
58-
)
53+
Box::pin(stream.into_stream().for_each(move |s| self.push_str(&s)))
5954
}
6055
}
6156

@@ -67,11 +62,6 @@ impl<'b> Extend<Cow<'b, str>> for String {
6762
where
6863
'b: 'a,
6964
{
70-
//TODO: This can just be: stream.into_stream().for_each(move |s| self.push_str(&s))
71-
Box::pin(
72-
stream
73-
.into_stream()
74-
.fold((), move |(), s| self.push_str(&s)),
75-
)
65+
Box::pin(stream.into_stream().for_each(move |s| self.push_str(&s)))
7666
}
7767
}

0 commit comments

Comments
 (0)