JStreamExt

Trait JStreamExt 

Source
pub trait JStreamExt: Stream + Sized {
    // Provided methods
    fn dedup(self) -> DedupStream<Self>
       where Self::Item: Hash { ... }
    fn fold_mut<T, F, Fut>(
        self,
        initial: T,
        handler: F,
    ) -> FoldMut<Self, T, F, Fut> 
       where Self: FusedStream,
             F: FnMut(&mut T, Self::Item) -> Fut,
             Fut: Future<Output = ()> { ... }
    fn first(self) -> StreamNth<Self>  { ... }
    fn nth(self, index: usize) -> StreamNth<Self>  { ... }
}
Expand description

Extensions to the Stream type which aren’t already covered in StreamExt.

This is implemented using a blanket impl for all Stream implementors.

Provided Methods§

Source

fn dedup(self) -> DedupStream<Self>
where Self::Item: Hash,

Given some stream where the item is Hash, return a stream which only emits the unique items emitted by the source stream.

You can think of this as “de-duplicating” this stream. Only the first instance of every unique item will be emitted.

This is implemented by computing and storing the hash (a u64 value) in a HashSet for each item emitted by the stream.

Source

fn fold_mut<T, F, Fut>(self, initial: T, handler: F) -> FoldMut<Self, T, F, Fut>
where Self: FusedStream, F: FnMut(&mut T, Self::Item) -> Fut, Fut: Future<Output = ()>,

fold, but with mutable references.

Turns this stream into a Future<Output=T>. You must provide some initial value of type T, and some function which accepts &mut T and Self::Item and returns Future<Output=()>.

After all items are emitted by this stream, the current value of T is emitted by the returned future.

If the stream emits no values, then the initial value of T is emitted.

Source

fn first(self) -> StreamNth<Self>

Turn this Stream into a Future which gives the first item emitted by this stream (in the form of an Option, because the stream doesn’t necessarily have to emit anything).

Source

fn nth(self, index: usize) -> StreamNth<Self>

Turn this Stream into a Future which gives the nth item emitted by this stream (in the form of an Option, because the stream doesn’t have to emit enough items to reach the index n).

It will only emit exactly the n’th item. If the stream completes before the nth item is reached, then the future will emit a value of None.

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<T> JStreamExt for T
where T: Stream + Sized,