FromStream for Arc<[T]> and Rc<[T]>

staging
Sunjay Varma 5 years ago
parent 63c6b1cb63
commit 2cf3f3f566

@ -1,5 +1,7 @@
use std::pin::Pin; use std::pin::Pin;
use std::borrow::Cow; use std::borrow::Cow;
use std::sync::Arc;
use std::rc::Rc;
use crate::stream::{Extend, FromStream, IntoStream}; use crate::stream::{Extend, FromStream, IntoStream};
@ -58,3 +60,39 @@ impl<T> FromStream<T> for Box<[T]> {
}) })
} }
} }
impl<T> FromStream<T> for Rc<[T]> {
#[inline]
fn from_stream<'a, S: IntoStream<Item = T>>(
stream: S,
) -> Pin<Box<dyn core::future::Future<Output = Self> + 'a>>
where
<S as IntoStream>::IntoStream: 'a,
{
let stream = stream.into_stream();
Box::pin(async move {
pin_utils::pin_mut!(stream);
Vec::from_stream(stream).await.into()
})
}
}
impl<T> FromStream<T> for Arc<[T]> {
#[inline]
fn from_stream<'a, S: IntoStream<Item = T>>(
stream: S,
) -> Pin<Box<dyn core::future::Future<Output = Self> + 'a>>
where
<S as IntoStream>::IntoStream: 'a,
{
let stream = stream.into_stream();
Box::pin(async move {
pin_utils::pin_mut!(stream);
Vec::from_stream(stream).await.into()
})
}
}

Loading…
Cancel
Save