Skip to main content

StreamExt

Trait StreamExt 

Source
pub trait StreamExt: Stream {
    // Provided method
    fn buffer_unordered_weighted<Fut>(
        self,
        max_weight: usize,
    ) -> BufferUnorderedWeighted<Self>
       where Self: Sized + Stream<Item = (usize, Fut)>,
             Fut: Future { ... }
}
Expand description

An extension trait for Streams that provides buffer_unordered_weighted.

Provided Methods§

Source

fn buffer_unordered_weighted<Fut>( self, max_weight: usize, ) -> BufferUnorderedWeighted<Self>
where Self: Sized + Stream<Item = (usize, Fut)>, Fut: Future,

An adaptor for creating a buffered list of pending futures (unordered), where each future has a different weight.

This stream must return values of type (usize, impl Future), where the usize indicates the weight of each future. This adaptor will buffer futures up to weight max_weight, and then return the outputs in the order in which they complete.

The weight may be exceeded if the last future to be queued has a weight greater than max_weight minus the total weight of currently executing futures. However, no further futures will be queued until the total weights of running futures falls below max_weight.

The adaptor will schedule futures in the order they’re returned by the stream, without doing any reordering based on weight.

The weight of a future can be zero, in which case it will not count towards the total weight.

The returned stream will be a stream of each future’s output.

§Examples

See the crate documentation for an example.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§

Source§

impl<T> StreamExt for T
where T: Stream + ?Sized,