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> 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>>
14 where
15 <S as IntoStream>::IntoStream: 'a,
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> 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>> {
32 let stream = stream.into_stream();
33
34 Box::pin(async move {
35 Cow::Owned(FromStream::from_stream(stream).await)
36 })
37 }
38}
39
40impl<T> FromStream<T> for Box<[T]> {
41 #[inline]
42 fn from_stream<'a, S: IntoStream<Item = T> + 'a>(
43 stream: S,
44 ) -> Pin<Box<dyn Future<Output = Self> + 'a>> {
45 let stream = stream.into_stream();
46
47 Box::pin(async move {
48 Vec::from_stream(stream).await.into_boxed_slice()
49 })
50 }
51}
52
53impl<T> FromStream<T> for Rc<[T]> {
54 #[inline]
55 fn from_stream<'a, S: IntoStream<Item = T> + 'a>(
56 stream: S,
57 ) -> Pin<Box<dyn Future<Output = Self> + 'a>> {
58 let stream = stream.into_stream();
59
60 Box::pin(async move {
61 Vec::from_stream(stream).await.into()
62 })
63 }
64}
65
66impl<T> FromStream<T> for Arc<[T]> {
67 #[inline]
68 fn from_stream<'a, S: IntoStream<Item = T> + 'a>(
69 stream: S,
70 ) -> Pin<Box<dyn Future<Output = Self> + 'a>> {
71 let stream = stream.into_stream();
72
73 Box::pin(async move {
74 Vec::from_stream(stream).await.into()
75 })
76 }
77}