async_std/string/
from_stream.rs1use 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>> {
12 let stream = stream.into_stream();
13
14 Box::pin(async move {
15 let mut out = String::new();
16 stream::extend(&mut out, stream).await;
17 out
18 })
19 }
20}
21
22impl<'b> FromStream<&'b char> for String {
23 #[inline]
24 fn from_stream<'a, S: IntoStream<Item = &'b char> + 'a>(
25 stream: S,
26 ) -> Pin<Box<dyn Future<Output = Self> + 'a>> {
27 let stream = stream.into_stream();
28
29 Box::pin(async move {
30 let mut out = String::new();
31 stream::extend(&mut out, stream).await;
32 out
33 })
34 }
35}
36
37impl<'b> FromStream<&'b str> for String {
38 #[inline]
39 fn from_stream<'a, S: IntoStream<Item = &'b str> + 'a>(
40 stream: S,
41 ) -> Pin<Box<dyn Future<Output = Self> + 'a>> {
42 let stream = stream.into_stream();
43
44 Box::pin(async move {
45 let mut out = String::new();
46 stream::extend(&mut out, stream).await;
47 out
48 })
49 }
50}
51
52impl FromStream<String> for String {
53 #[inline]
54 fn from_stream<'a, S: IntoStream<Item = String> + 'a>(
55 stream: S,
56 ) -> Pin<Box<dyn Future<Output = Self> + 'a>> {
57 let stream = stream.into_stream();
58
59 Box::pin(async move {
60 let mut out = String::new();
61 stream::extend(&mut out, stream).await;
62 out
63 })
64 }
65}
66
67impl<'b> FromStream<Cow<'b, str>> for String {
68 #[inline]
69 fn from_stream<'a, S: IntoStream<Item = Cow<'b, str>> + 'a>(
70 stream: S,
71 ) -> Pin<Box<dyn Future<Output = Self> + 'a>> {
72 let stream = stream.into_stream();
73
74 Box::pin(async move {
75 let mut out = String::new();
76 stream::extend(&mut out, stream).await;
77 out
78 })
79 }
80}