mirror of
https://github.com/async-rs/async-std.git
synced 2025-01-16 10:49:55 +00:00
FromStream for Arc<[T]> and Rc<[T]>
This commit is contained in:
parent
63c6b1cb63
commit
2cf3f3f566
1 changed files with 38 additions and 0 deletions
|
@ -1,5 +1,7 @@
|
|||
use std::pin::Pin;
|
||||
use std::borrow::Cow;
|
||||
use std::sync::Arc;
|
||||
use std::rc::Rc;
|
||||
|
||||
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…
Reference in a new issue