use std::borrow::Cow; use std::pin::Pin; use std::rc::Rc; use std::sync::Arc; use crate::stream::{Extend, FromStream, IntoStream}; impl FromStream for Vec { #[inline] fn from_stream<'a, S: IntoStream>( stream: S, ) -> Pin + 'a>> where ::IntoStream: 'a, { let stream = stream.into_stream(); Box::pin(async move { pin_utils::pin_mut!(stream); let mut out = vec![]; out.stream_extend(stream).await; out }) } } impl<'b, T: Clone> FromStream for Cow<'b, [T]> { #[inline] fn from_stream<'a, S: IntoStream>( stream: S, ) -> Pin + 'a>> where ::IntoStream: 'a, { let stream = stream.into_stream(); Box::pin(async move { pin_utils::pin_mut!(stream); Cow::Owned(FromStream::from_stream(stream).await) }) } } impl FromStream for Box<[T]> { #[inline] fn from_stream<'a, S: IntoStream>( stream: S, ) -> Pin + 'a>> where ::IntoStream: 'a, { let stream = stream.into_stream(); Box::pin(async move { pin_utils::pin_mut!(stream); Vec::from_stream(stream).await.into_boxed_slice() }) } } impl FromStream for Rc<[T]> { #[inline] fn from_stream<'a, S: IntoStream>( stream: S, ) -> Pin + 'a>> where ::IntoStream: 'a, { let stream = stream.into_stream(); Box::pin(async move { pin_utils::pin_mut!(stream); Vec::from_stream(stream).await.into() }) } } impl FromStream for Arc<[T]> { #[inline] fn from_stream<'a, S: IntoStream>( stream: S, ) -> Pin + 'a>> where ::IntoStream: 'a, { let stream = stream.into_stream(); Box::pin(async move { pin_utils::pin_mut!(stream); Vec::from_stream(stream).await.into() }) } }