[][src]Trait iterstream::IterStream

pub trait IterStream: Iterator where
    Self: 'static + Sized + Send,
    Self::Item: Send
{ fn to_stream(
        self,
        buffer_size: usize
    ) -> Result<Receiver<Self::Item>, Error> { ... }
fn to_stream_with_pool(
        self,
        buffer_size: usize,
        pool: ThreadPool
    ) -> Receiver<Self::Item> { ... } }

A trait that converts an Iterator to an asynchronous Stream that polls the iterator in a background task

Provided methods

fn to_stream(self, buffer_size: usize) -> Result<Receiver<Self::Item>, Error>

Creates a stream from an iterator. The stream is actually a mpsc::Receiver

The buffer_size parameter is directly used in the creation of the underlying channel

A new ThreadPool is created for each call to this function. If you need multiple streams, you probably want to use to_stream_with_pool instead

Example

use iterstream::IterStream;
use futures::stream::StreamExt;

let vals = vec![1, 2, 3, 4, 5];
let stream = vals.into_iter().to_stream(10).unwrap();
let c: Vec<_> = stream.collect().await;
assert_eq!(vec![1,2,3,4, 5], c);

fn to_stream_with_pool(
    self,
    buffer_size: usize,
    pool: ThreadPool
) -> Receiver<Self::Item>

Creates a stream from an iterator. The stream is actually a mpsc::Receiver

The buffer_size parameter is directly used in the creation of the underlying channel

The task that will poll the iterator is created from the given ThreadPool

Example

use iterstream::IterStream;
use futures::stream::StreamExt;
use futures::executor::ThreadPool;

let vals = vec![1, 2, 3, 4, 5];
let stream = vals.into_iter().to_stream_with_pool(10, ThreadPool::new().unwrap());
let c: Vec<_> = stream.collect().await;
assert_eq!(vec![1,2,3,4, 5], c);
Loading content...

Implementors

impl<I> IterStream for I where
    I: 'static + Iterator + Send,
    I::Item: Send
[src]

Implemenation of the IterStream trait for all Iterators

Loading content...