Trait streamtools::StreamTools
source · pub trait StreamTools: Stream {
// Provided methods
fn fast_forward(self) -> FastForward<Self>
where Self: Sized { ... }
fn flatten_switch(self) -> FlattenSwitch<Self>
where Self::Item: Stream,
Self: Sized { ... }
fn flat_map_switch<U, F>(self, f: F) -> FlattenSwitch<Map<Self, F>>
where F: FnMut(Self::Item) -> U,
U: Stream,
Self: Sized { ... }
fn sample<S: Stream>(self, sampler: S) -> Sample<Self, S>
where Self: Sized { ... }
fn sample_by_duration(
self,
duration: Duration
) -> Sample<Self, IntervalStream>
where Self: Sized { ... }
fn sample_by_interval(
self,
interval: Interval
) -> Sample<Self, IntervalStream>
where Self: Sized { ... }
fn throttle_last<'a>(self, duration: Duration) -> ThrottleLast<Self>
where Self: Sized + Send + 'a { ... }
fn record_delay(self) -> RecordDelay<Self>
where Self: Sized { ... }
}
Expand description
An extension trait for the Stream
trait that provides a variety of
convenient combinator functions.
Provided Methods§
sourcefn fast_forward(self) -> FastForward<Self>where
Self: Sized,
fn fast_forward(self) -> FastForward<Self>where Self: Sized,
Fast-forwards to the latest value on the underlying stream by polling the underyling until it is Pending
.
When the underlying stream terminates, this stream will yield the last value on the underlying stream, if it has not already been yielded.
This behaves like a WatchStream
but can be applied to arbitrary streams without requiring a channel.
sourcefn flatten_switch(self) -> FlattenSwitch<Self>where
Self::Item: Stream,
Self: Sized,
fn flatten_switch(self) -> FlattenSwitch<Self>where Self::Item: Stream, Self: Sized,
sourcefn flat_map_switch<U, F>(self, f: F) -> FlattenSwitch<Map<Self, F>>where
F: FnMut(Self::Item) -> U,
U: Stream,
Self: Sized,
fn flat_map_switch<U, F>(self, f: F) -> FlattenSwitch<Map<Self, F>>where F: FnMut(Self::Item) -> U, U: Stream, Self: Sized,
Maps a stream like StreamExt::map
but flattens nested [Stream]s using flatten_switch
.
sourcefn sample_by_duration(self, duration: Duration) -> Sample<Self, IntervalStream>where
Self: Sized,
fn sample_by_duration(self, duration: Duration) -> Sample<Self, IntervalStream>where Self: Sized,
tokio-time
only.Samples values from the stream at intervals of length duration
. This is a convenience method which invokes sample_by_interval
.
The stream terminates when the input stream terminates.
Uses the default MissedTickBehavior
to create an Interval
. If another is needed, then configure it on an Interval
and
use sample_by_interval
instead of this method.
This mirrors the behaviour of the Sample operator in ReactiveX.
sourcefn sample_by_interval(self, interval: Interval) -> Sample<Self, IntervalStream>where
Self: Sized,
fn sample_by_interval(self, interval: Interval) -> Sample<Self, IntervalStream>where Self: Sized,
tokio-time
only.sourcefn throttle_last<'a>(self, duration: Duration) -> ThrottleLast<Self>where
Self: Sized + Send + 'a,
fn throttle_last<'a>(self, duration: Duration) -> ThrottleLast<Self>where Self: Sized + Send + 'a,
tokio-time
only.Throttles values from the stream at intervals of length duration
, skipping all but the last value seen in each interval.
Note that this behaves exactly the same as applying fast_forward
followed by tokio’s throttle
.
The stream terminates after the input stream terminates and any pending timeout expires for the throttling.
sourcefn record_delay(self) -> RecordDelay<Self>where
Self: Sized,
fn record_delay(self) -> RecordDelay<Self>where Self: Sized,
test-util
only.Records the duration relative to the time this method was called at which each item is yielded from the stream.