parallel_stream/par_stream/
mod.rs1use async_std::future::Future;
2use async_std::task::{Context, Poll};
3
4use std::pin::Pin;
5
6use crate::FromParallelStream;
7
8pub use for_each::ForEach;
9pub use map::Map;
10pub use next::NextFuture;
11pub use take::Take;
12
13mod for_each;
14mod map;
15mod next;
16mod take;
17
18pub trait ParallelStream: Sized + Send + Sync + Unpin + 'static {
20 type Item: Send;
22
23 fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>>;
25
26 fn limit(self, limit: impl Into<Option<usize>>) -> Self;
28
29 fn get_limit(&self) -> Option<usize>;
31
32 fn map<F, T, Fut>(self, f: F) -> Map<T>
35 where
36 F: FnMut(Self::Item) -> Fut + Send + Sync + Copy + 'static,
37 T: Send + 'static,
38 Fut: Future<Output = T> + Send,
39 {
40 Map::new(self, f)
41 }
42
43 fn next(&mut self) -> NextFuture<'_, Self> {
46 NextFuture::new(self)
47 }
48
49 fn take(self, n: usize) -> Take<Self>
51 where
52 Self: Sized,
53 {
54 Take::new(self, n)
55 }
56
57 fn for_each<F, Fut>(self, f: F) -> ForEach
59 where
60 F: FnMut(Self::Item) -> Fut + Send + Sync + Copy + 'static,
61 Fut: Future<Output = ()> + Send,
62 {
63 ForEach::new(self, f)
64 }
65
66 fn collect<'a, B>(self) -> Pin<Box<dyn Future<Output = B> + 'a + Send>>
72 where
73 Self: Sized + 'a,
74 B: FromParallelStream<Self::Item>,
75 {
76 FromParallelStream::from_par_stream(self)
77 }
78}