2
0
Fork 1
mirror of https://github.com/async-rs/async-std.git synced 2025-10-22 12:26:37 +00:00
async-std/src/string/from_stream.rs
Yoshua Wuyts c82b1efb69
fix(stream): add send guards on collect
Closes #639 

Co-authored-by: dignifiedquire <me@dignifiedquire.com>
2020-06-27 16:46:14 +02:00

95 lines
2.3 KiB
Rust

use std::borrow::Cow;
use std::pin::Pin;
use crate::prelude::*;
use crate::stream::{self, FromStream, IntoStream};
impl FromStream<char> for String {
#[inline]
fn from_stream<'a, S: IntoStream<Item = char> + 'a>(
stream: S,
) -> Pin<Box<dyn Future<Output = Self> + 'a + Send>>
where
<S as IntoStream>::IntoStream: Send,
{
let stream = stream.into_stream();
Box::pin(async move {
let mut out = String::new();
stream::extend(&mut out, stream).await;
out
})
}
}
impl<'b> FromStream<&'b char> for String {
#[inline]
fn from_stream<'a, S: IntoStream<Item = &'b char> + 'a>(
stream: S,
) -> Pin<Box<dyn Future<Output = Self> + 'a + Send>>
where
<S as IntoStream>::IntoStream: Send,
{
let stream = stream.into_stream();
Box::pin(async move {
let mut out = String::new();
stream::extend(&mut out, stream).await;
out
})
}
}
impl<'b> FromStream<&'b str> for String {
#[inline]
fn from_stream<'a, S: IntoStream<Item = &'b str> + 'a>(
stream: S,
) -> Pin<Box<dyn Future<Output = Self> + 'a + Send>>
where
<S as IntoStream>::IntoStream: Send,
{
let stream = stream.into_stream();
Box::pin(async move {
let mut out = String::new();
stream::extend(&mut out, stream).await;
out
})
}
}
impl FromStream<String> for String {
#[inline]
fn from_stream<'a, S: IntoStream<Item = String> + 'a>(
stream: S,
) -> Pin<Box<dyn Future<Output = Self> + 'a + Send>>
where
<S as IntoStream>::IntoStream: Send,
{
let stream = stream.into_stream();
Box::pin(async move {
let mut out = String::new();
stream::extend(&mut out, stream).await;
out
})
}
}
impl<'b> FromStream<Cow<'b, str>> for String {
#[inline]
fn from_stream<'a, S: IntoStream<Item = Cow<'b, str>> + 'a>(
stream: S,
) -> Pin<Box<dyn Future<Output = Self> + 'a + Send>>
where
<S as IntoStream>::IntoStream: Send,
{
let stream = stream.into_stream();
Box::pin(async move {
let mut out = String::new();
stream::extend(&mut out, stream).await;
out
})
}
}