async_rx

Trait StreamExt

Source
pub trait StreamExt: Stream + Sized {
    // Provided methods
    fn dedup(self) -> Dedup<Self>
       where Self::Item: Clone + PartialEq { ... }
    fn dedup_by_key<T, F>(self, key_fn: F) -> DedupByKey<Self, T, F>
       where T: PartialEq,
             F: FnMut(&Self::Item) -> T { ... }
    fn batch_with<S>(self, batch_done_stream: S) -> BatchWith<Self, S>
       where S: Stream<Item = ()> { ... }
    fn switch(self) -> Switch<Self>
       where Self::Item: Stream { ... }
}
Expand description

Extensions to the Stream trait.

Provided Methods§

Source

fn dedup(self) -> Dedup<Self>
where Self::Item: Clone + PartialEq,

Deduplicate consecutive identical items.

To be able to immediately yield items of the underlying stream once it is produced, but still compare them to the next ones, Dedup keeps a clone of the value that was produced last. If cloning the inner value is expensive but only part of it is used for comparison, you can use dedup_by_key as a more efficient alternative.

Source

fn dedup_by_key<T, F>(self, key_fn: F) -> DedupByKey<Self, T, F>
where T: PartialEq, F: FnMut(&Self::Item) -> T,

Deduplicate consecutive items that the given function produces the same key for.

Source

fn batch_with<S>(self, batch_done_stream: S) -> BatchWith<Self, S>
where S: Stream<Item = ()>,

Buffer the items from self until batch_done_stream produces a value, and return all buffered values in one batch.

batch_done_stream is polled after all ready items from self has been read.

Examples for possible batch_done_streams:

  • futures_channel::mpsc::Receiver<()>
  • tokio_stream::wrappers::IntervalStream with its item type mapped to () using .map(|_| ()) (use tokio_stream::StreamExt for map)
Source

fn switch(self) -> Switch<Self>
where Self::Item: Stream,

Flattens a stream of streams by always keeping one inner stream and yielding its items until the outer stream produces a new inner stream, at which point the inner stream to yield items from is switched to the new one.

Equivalent to RxJS’es switchAll.

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<S: Stream> StreamExt for S