parallel_stream/
from_parallel_stream.rs1use core::future::Future;
2use core::pin::Pin;
3
4use crate::IntoParallelStream;
5
6pub trait FromParallelStream<T: Send> {
8 fn from_par_stream<'a, S>(stream: S) -> Pin<Box<dyn Future<Output = Self> + 'a + Send>>
10 where
11 S: IntoParallelStream<Item = T> + 'a + Send;
12}
13
14#[async_std::test]
15async fn is_send() {
16 use crate::prelude::*;
17 async_std::task::spawn(async move {
18 let v: Vec<usize> = vec![1, 2, 3, 4];
19 let stream = v.into_par_stream().map(|n| async move { n * n });
20 let mut res = Vec::from_par_stream(stream).await;
21 res.sort_unstable();
22 assert_eq!(res, vec![1, 4, 9, 16]);
23 })
24 .await;
25}