Trait async_rx::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 = ()> { ... }
}
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)

Implementors§

source§

impl<S: Stream> StreamExt for S