Skip to main content

FromParallelStream

Trait FromParallelStream 

Source
pub trait FromParallelStream<T: Send> {
    // Required method
    fn from_par_stream<'a, S>(
        stream: S,
    ) -> Pin<Box<dyn Future<Output = Self> + Send + 'a>>
       where S: IntoParallelStream<Item = T> + 'a + Send;
}
Expand description

Conversion from a ParallelStream.

Required Methods§

Source

fn from_par_stream<'a, S>( stream: S, ) -> Pin<Box<dyn Future<Output = Self> + Send + 'a>>
where S: IntoParallelStream<Item = T> + 'a + Send,

Creates a value from a stream.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<T: Send> FromParallelStream<T> for Vec<T>

Collect items from a parallel stream into a vector.

§Examples

use parallel_stream::prelude::*;

#[async_std::main]
async fn main() {
    let v = vec![1, 2, 3, 4];
    let mut stream = v.into_par_stream().map(|n| async move { n * n });
    let mut res = Vec::from_par_stream(stream).await;
    res.sort();
    assert_eq!(res, vec![1, 4, 9, 16]);
}
Source§

fn from_par_stream<'a, S>( stream: S, ) -> Pin<Box<dyn Future<Output = Self> + Send + 'a>>
where S: IntoParallelStream<Item = T> + Send + 'a,

Implementors§