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§
Sourcefn dedup(self) -> Dedup<Self>
fn dedup(self) -> Dedup<Self>
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.
Sourcefn dedup_by_key<T, F>(self, key_fn: F) -> DedupByKey<Self, T, F>
fn dedup_by_key<T, F>(self, key_fn: F) -> DedupByKey<Self, T, F>
Deduplicate consecutive items that the given function produces the same key for.
Sourcefn batch_with<S>(self, batch_done_stream: S) -> BatchWith<Self, S>
fn batch_with<S>(self, batch_done_stream: S) -> BatchWith<Self, S>
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_stream
s:
futures_channel::mpsc::Receiver<()>
tokio_stream::wrappers::IntervalStream
with its item type mapped to()
using.map(|_| ())
(use tokio_stream::StreamExt
formap
)
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.