async_std/vec/
from_stream.rs1use std::borrow::Cow;
2use std::pin::Pin;
3use std::rc::Rc;
4use std::sync::Arc;
5
6use crate::prelude::*;
7use crate::stream::{self, FromStream, IntoStream};
8
9impl<T: Send> FromStream<T> for Vec<T> {
10 #[inline]
11 fn from_stream<'a, S: IntoStream<Item = T>>(
12 stream: S,
13 ) -> Pin<Box<dyn Future<Output = Self> + 'a + Send>>
14 where
15 <S as IntoStream>::IntoStream: 'a + Send,
16 {
17 let stream = stream.into_stream();
18
19 Box::pin(async move {
20 let mut out = vec![];
21 stream::extend(&mut out, stream).await;
22 out
23 })
24 }
25}
26
27impl<'b, T: Clone + Send> FromStream<T> for Cow<'b, [T]> {
28 #[inline]
29 fn from_stream<'a, S: IntoStream<Item = T> + 'a>(
30 stream: S,
31 ) -> Pin<Box<dyn Future<Output = Self> + 'a + Send>>
32 where
33 <S as IntoStream>::IntoStream: Send
34 {
35 let stream = stream.into_stream();
36
37 Box::pin(async move {
38 Cow::Owned(FromStream::from_stream(stream).await)
39 })
40 }
41}
42
43impl<T: Send> FromStream<T> for Box<[T]> {
44 #[inline]
45 fn from_stream<'a, S: IntoStream<Item = T> + '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 Vec::from_stream(stream).await.into_boxed_slice()
55 })
56 }
57}
58
59impl<T: Send> FromStream<T> for Rc<[T]> {
60 #[inline]
61 fn from_stream<'a, S: IntoStream<Item = T> + 'a>(
62 stream: S,
63 ) -> Pin<Box<dyn Future<Output = Self> + 'a + Send>>
64 where
65 <S as IntoStream>::IntoStream: Send
66 {
67 let stream = stream.into_stream();
68
69 Box::pin(async move {
70 Vec::from_stream(stream).await.into()
71 })
72 }
73}
74
75impl<T: Send> FromStream<T> for Arc<[T]> {
76 #[inline]
77 fn from_stream<'a, S: IntoStream<Item = T> + 'a>(
78 stream: S,
79 ) -> Pin<Box<dyn Future<Output = Self> + 'a + Send>>
80 where
81 <S as IntoStream>::IntoStream: Send
82 {
83 let stream = stream.into_stream();
84
85 Box::pin(async move {
86 Vec::from_stream(stream).await.into()
87 })
88 }
89}