pub trait StreamExt: Stream {
// Provided method
fn progress<'a, F>(
self,
theme: impl Into<Theme<'a>>,
fraction_fn: F,
) -> StreamProgressBuilder<'a, Self, F, Pending<&'static str>>
where Self: Sized,
F: FnMut(usize, &Self::Item) -> f64 + Unpin { ... }
}Expand description
Extension trait that adds progress display to streams.
Each time the wrapped stream yields an item, a spinner, progress bar and optional message are rendered to stdout. The line is cleared when the stream ends.
Import this trait and call progress() on any stream to obtain a
StreamProgressBuilder.
Provided Methods§
Sourcefn progress<'a, F>(
self,
theme: impl Into<Theme<'a>>,
fraction_fn: F,
) -> StreamProgressBuilder<'a, Self, F, Pending<&'static str>>
fn progress<'a, F>( self, theme: impl Into<Theme<'a>>, fraction_fn: F, ) -> StreamProgressBuilder<'a, Self, F, Pending<&'static str>>
Wrap this stream in a StreamProgressBuilder driven by theme.
theme accepts a Theme or a bare Spinner (converted via
Into). fraction_fn is called for every item and must return a value between 0.0 (no
progress) and 1.0 (complete). It receives the monotonically increasing item index
(starting at 1) and a reference to the item, so progress can be derived from either the
count or the item content.
Use with_messages on the returned builder to also
display dynamic messages.
§Example
use futures_lite::StreamExt as _;
use strides::stream::StreamExt;
use strides::spinner::styles::DOTS_3;
let total = 100;
futures_lite::stream::iter(0..total)
.progress(DOTS_3, move |i, _| i as f64 / total as f64)
.count()
.await;