async_std/string/
from_stream.rs

1use std::borrow::Cow;
2use std::pin::Pin;
3
4use crate::prelude::*;
5use crate::stream::{self, FromStream, IntoStream};
6
7impl FromStream<char> for String {
8    #[inline]
9    fn from_stream<'a, S: IntoStream<Item = char> + 'a>(
10        stream: S,
11    ) -> Pin<Box<dyn Future<Output = Self> + 'a + Send>> 
12    where
13        <S as IntoStream>::IntoStream: Send,
14    {
15        let stream = stream.into_stream();
16
17        Box::pin(async move {
18            let mut out = String::new();
19            stream::extend(&mut out, stream).await;
20            out
21        })
22    }
23}
24
25impl<'b> FromStream<&'b char> for String {
26    #[inline]
27    fn from_stream<'a, S: IntoStream<Item = &'b char> + 'a>(
28        stream: S,
29    ) -> Pin<Box<dyn Future<Output = Self> + 'a + Send>> 
30    where
31        <S as IntoStream>::IntoStream: Send,
32    {
33        let stream = stream.into_stream();
34
35        Box::pin(async move {
36            let mut out = String::new();
37            stream::extend(&mut out, stream).await;
38            out
39        })
40    }
41}
42
43impl<'b> FromStream<&'b str> for String {
44    #[inline]
45    fn from_stream<'a, S: IntoStream<Item = &'b str> + 'a>(
46        stream: S,
47    ) -> Pin<Box<dyn Future<Output = Self> + 'a + Send>> 
48    where
49        <S as IntoStream>::IntoStream: Send,
50    {
51        let stream = stream.into_stream();
52
53        Box::pin(async move {
54            let mut out = String::new();
55            stream::extend(&mut out, stream).await;
56            out
57        })
58    }
59}
60
61impl FromStream<String> for String {
62    #[inline]
63    fn from_stream<'a, S: IntoStream<Item = String> + 'a>(
64        stream: S,
65    ) -> Pin<Box<dyn Future<Output = Self> + 'a + Send>> 
66    where
67        <S as IntoStream>::IntoStream: Send,
68    {
69        let stream = stream.into_stream();
70
71        Box::pin(async move {
72            let mut out = String::new();
73            stream::extend(&mut out, stream).await;
74            out
75        })
76    }
77}
78
79impl<'b> FromStream<Cow<'b, str>> for String {
80    #[inline]
81    fn from_stream<'a, S: IntoStream<Item = Cow<'b, str>> + 'a>(
82        stream: S,
83    ) -> Pin<Box<dyn Future<Output = Self> + 'a + Send>> 
84    where
85        <S as IntoStream>::IntoStream: Send,
86    {
87        let stream = stream.into_stream();
88
89        Box::pin(async move {
90            let mut out = String::new();
91            stream::extend(&mut out, stream).await;
92            out
93        })
94    }
95}