IterExt

Trait IterExt 

Source
pub trait IterExt: IntoIterator {
    // Provided methods
    fn merge(self) -> MergeBounded<Self::Item>
       where Self: Sized,
             Self::Item: Stream { ... }
    fn merge_unbounded(self) -> MergeUnbounded<Self::Item>
       where Self: Sized,
             Self::Item: Stream + Unpin { ... }
    fn join_all(self) -> JoinAll<Self::Item> 
       where Self: Sized,
             Self::Item: Future { ... }
    fn try_join_all(self) -> TryJoinAll<Self::Item> 
       where Self: Sized,
             Self::Item: TryFuture { ... }
    fn into_unordered_stream(self) -> FuturesUnorderedBounded<Self::Item>
       where Self: Sized,
             Self::Item: Future { ... }
    fn into_unordered_stream_unbounded(self) -> FuturesUnordered<Self::Item>
       where Self: Sized,
             Self::Item: Future { ... }
    fn into_ordered_stream(self) -> FuturesOrderedBounded<Self::Item>
       where Self: Sized,
             Self::Item: Future { ... }
    fn into_ordered_stream_unbounded(self) -> FuturesOrdered<Self::Item>
       where Self: Sized,
             Self::Item: Future { ... }
}
Expand description

Concurrency extensions for iterators of streams and futures.

Provided Methods§

Source

fn merge(self) -> MergeBounded<Self::Item>
where Self: Sized, Self::Item: Stream,

Combines an iterator of streams into a single stream, yielding items as they arrive.

Returns MergeBounded, which has a fixed capacity and thus no further streams may be added.

§Example
use futures::{stream, StreamExt};
use futures_buffered::IterExt;

let res = [stream::iter(0..3), stream::iter(0..5)]
    .merge()
    .count()
    .await;
assert_eq!(res, 3 + 5);
Source

fn merge_unbounded(self) -> MergeUnbounded<Self::Item>
where Self: Sized, Self::Item: Stream + Unpin,

Combines an iterator of streams into a single stream, yielding items as they arrive.

This is like IterExt::merge, but returns MergeUnbounded, to which further streams may be added with MergeUnbounded::push. If you don’t need to add more streams, use IterExt::merge, which has better performance characteristics.

Source

fn join_all(self) -> JoinAll<Self::Item>
where Self: Sized, Self::Item: Future,

Waits for all futures to complete, returning a Vec of their outputs.

All futures are driven concurrently to completion, and their results are collected into a Vec in same order as they were provided.

See join_all for details.

§Example
use futures_buffered::IterExt;
let res: Vec<_> = [3, 2, 1]
    .map(|x| async move { x })
    .join_all()
    .await;
assert_eq!(res, vec![3, 2, 1]);
Source

fn try_join_all(self) -> TryJoinAll<Self::Item>
where Self: Sized, Self::Item: TryFuture,

Waits for all futures to complete, returning a Result<Vec<T>, E>.

If any future returns an error then all other futures will be canceled and the error will be returned immediately. If all futures complete successfully, then the returned future will succeed with a Vec of all the successful results in the same order as the futures were provided.

See try_join_all for details.

Source

fn into_unordered_stream(self) -> FuturesUnorderedBounded<Self::Item>
where Self: Sized, Self::Item: Future,

Combines an iterator of futures into a concurrent stream, yielding items as they arrive.

The futures are polled concurrently and items are yielded in the order of completion.

Returns FuturesUnorderedBounded, which has a fixed capacity so no further futures can be added to the stream.

§Example
use futures::StreamExt;
use futures_buffered::IterExt;
use tokio::time::{sleep, Duration};

let res: Vec<_> = [3, 2, 1]
    .map(|x| async move {
        sleep(Duration::from_millis(x * 10)).await;
        x
    })
    .into_unordered_stream()
    .collect()
    .await;
assert_eq!(res, vec![1, 2, 3]);
Source

fn into_unordered_stream_unbounded(self) -> FuturesUnordered<Self::Item>
where Self: Sized, Self::Item: Future,

Combines an iterator of futures into a concurrent stream, yielding items as they arrive.

The futures are polled concurrently and items are yielded in the order of completion.

Returns FuturesUnordered, which can grow capacity on demand, so further futures can be added to the stream via FuturesUnordered::push.

Source

fn into_ordered_stream(self) -> FuturesOrderedBounded<Self::Item>
where Self: Sized, Self::Item: Future,

Combines an iterator of futures into a concurrent stream, yielding items in their original order.

The futures are polled concurrently and items are yielded in the order of the source iterator.

Returns FuturesOrderedBounded, which has a fixed capacity so no further futures can be added to the stream.

§Example
use futures::StreamExt;
use futures_buffered::IterExt;
use tokio::time::{sleep, Duration};

let res: Vec<_> = [3, 2, 1]
    .map(|x| async move {
        sleep(Duration::from_millis(x * 10)).await;
        x
    })
    .into_ordered_stream()
    .collect()
    .await;
assert_eq!(res, vec![3, 2, 1]);
Source

fn into_ordered_stream_unbounded(self) -> FuturesOrdered<Self::Item>
where Self: Sized, Self::Item: Future,

Combines an iterator of futures into a concurrent stream, yielding items in their original order.

The futures are polled concurrently and items are yielded in the order of the source iterator.

Returns FuturesOrdered, which can grow capacity on demand, so further futures can be added to the stream via FuturesOrdered::push_back or FuturesOrdered::push_front.

Implementors§

Source§

impl<T> IterExt for T
where T: IntoIterator,