Trait ParallelStream

Source
pub trait ParallelStream:
    Sized
    + Send
    + Sync
    + Unpin
    + 'static {
    type Item: Send;

    // Required methods
    fn poll_next(
        self: Pin<&mut Self>,
        cx: &mut Context<'_>,
    ) -> Poll<Option<Self::Item>>;
    fn limit(self, limit: impl Into<Option<usize>>) -> Self;
    fn get_limit(&self) -> Option<usize>;

    // Provided methods
    fn map<F, T, Fut>(self, f: F) -> Map<T>
       where F: FnMut(Self::Item) -> Fut + Send + Sync + Copy + 'static,
             T: Send + 'static,
             Fut: Future<Output = T> + Send { ... }
    fn next(&mut self) -> NextFuture<'_, Self> { ... }
    fn take(self, n: usize) -> Take<Self>
       where Self: Sized { ... }
    fn for_each<F, Fut>(self, f: F) -> ForEach 
       where F: FnMut(Self::Item) -> Fut + Send + Sync + Copy + 'static,
             Fut: Future<Output = ()> + Send { ... }
    fn collect<'a, B>(self) -> Pin<Box<dyn Future<Output = B> + Send + 'a>>
       where Self: Sized + 'a,
             B: FromParallelStream<Self::Item> { ... }
}
Expand description

Parallel version of the standard Stream trait.

Required Associated Types§

Source

type Item: Send

The type of items yielded by this stream.

Required Methods§

Source

fn poll_next( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Option<Self::Item>>

Attempts to receive the next item from the stream.

Source

fn limit(self, limit: impl Into<Option<usize>>) -> Self

Set a max concurrency limit

Source

fn get_limit(&self) -> Option<usize>

Get the max concurrency limit

Provided Methods§

Source

fn map<F, T, Fut>(self, f: F) -> Map<T>
where F: FnMut(Self::Item) -> Fut + Send + Sync + Copy + 'static, T: Send + 'static, Fut: Future<Output = T> + Send,

Applies f to each item of this stream in parallel, producing a new stream with the results.

Source

fn next(&mut self) -> NextFuture<'_, Self>

Applies f to each item of this stream in parallel, producing a new stream with the results.

Source

fn take(self, n: usize) -> Take<Self>
where Self: Sized,

Creates a stream that yields its first n elements.

Source

fn for_each<F, Fut>(self, f: F) -> ForEach
where F: FnMut(Self::Item) -> Fut + Send + Sync + Copy + 'static, Fut: Future<Output = ()> + Send,

Applies f to each item of this stream in parallel.

Source

fn collect<'a, B>(self) -> Pin<Box<dyn Future<Output = B> + Send + 'a>>
where Self: Sized + 'a, B: FromParallelStream<Self::Item>,

Transforms a stream into a collection.

collect() can take anything streamable, and turn it into a relevant collection. This is one of the more powerful methods in the async standard library, used in a variety of contexts.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<S: Stream + Send + Sync + Unpin + 'static> ParallelStream for FromStream<S>
where S::Item: Send,

Source§

type Item = <S as Stream>::Item

Source§

impl<S: ParallelStream> ParallelStream for Take<S>

Source§

impl<T: Send + 'static> ParallelStream for Map<T>

Source§

type Item = T

Source§

impl<T: Send + Sync + 'static> ParallelStream for IntoParStream<T>

Source§

type Item = T