Implementing Extend for String in terms of for_each now that that's been added

pull/266/head
Sunjay Varma 5 years ago
parent d6f16b6a17
commit 09a15ef116

@ -10,24 +10,25 @@ impl Extend<char> for String {
stream: S,
) -> Pin<Box<dyn Future<Output = ()> + 'a>> {
let stream = stream.into_stream();
//TODO: Add this back in when size_hint is added to stream
//TODO: Add this back in when size_hint is added to Stream/StreamExt
// let (lower_bound, _) = stream.size_hint();
// self.reserve(lower_bound);
//TODO: This can just be: stream.for_each(move |c| self.push(c))
Box::pin(stream.fold((), move |(), c| self.push(c)))
Box::pin(stream.for_each(move |c| self.push(c)))
}
}
impl<'b> Extend<&'b char> for String {
fn stream_extend<'a, S: IntoStream<Item = &'b char> + 'a>(
&'a mut self,
stream: S,
//TODO: Remove the underscore when uncommenting the body of this impl
_stream: S,
) -> Pin<Box<dyn Future<Output = ()> + 'a>>
where
'b: 'a,
{
//TODO: Box::pin(stream.into_stream().copied())
//TODO: This can be uncommented when `copied` is added to Stream/StreamExt
//Box::pin(stream.into_stream().copied())
unimplemented!()
}
}
@ -40,8 +41,7 @@ impl<'b> Extend<&'b str> for String {
where
'b: 'a,
{
//TODO: This can just be: stream.into_stream().for_each(move |s| self.push_str(s))
Box::pin(stream.into_stream().fold((), move |(), s| self.push_str(s)))
Box::pin(stream.into_stream().for_each(move |s| self.push_str(s)))
}
}
@ -50,12 +50,7 @@ impl Extend<String> for String {
&'a mut self,
stream: S,
) -> Pin<Box<dyn Future<Output = ()> + 'a>> {
//TODO: This can just be: stream.into_stream().for_each(move |s| self.push_str(&s))
Box::pin(
stream
.into_stream()
.fold((), move |(), s| self.push_str(&s)),
)
Box::pin(stream.into_stream().for_each(move |s| self.push_str(&s)))
}
}
@ -67,11 +62,6 @@ impl<'b> Extend<Cow<'b, str>> for String {
where
'b: 'a,
{
//TODO: This can just be: stream.into_stream().for_each(move |s| self.push_str(&s))
Box::pin(
stream
.into_stream()
.fold((), move |(), s| self.push_str(&s)),
)
Box::pin(stream.into_stream().for_each(move |s| self.push_str(&s)))
}
}

Loading…
Cancel
Save