Skip to main content

StreamExt

Trait StreamExt 

Source
pub trait StreamExt: Stream {
Show 33 methods // Provided methods fn next(&mut self) -> Next<'_, Self> where Self: Unpin { ... } fn map<T, F>(self, f: F) -> Map<Self, F> where Self: Sized, F: FnMut(Self::Item) -> T { ... } fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F> where Self: Sized, F: FnMut(Self::Item) -> Fut, Fut: Future { ... } fn chain<S2>(self, other: S2) -> Chain<Self, S2> where Self: Sized, S2: Stream<Item = Self::Item> { ... } fn merge(self, other: Self) -> Merge<Self> where Self: Sized { ... } fn zip<S2>(self, other: S2) -> Zip<Self, S2> where Self: Sized, S2: Stream { ... } fn filter<P>(self, predicate: P) -> Filter<Self, P> where Self: Sized, P: FnMut(&Self::Item) -> bool { ... } fn filter_map<T, F>(self, f: F) -> FilterMap<Self, F> where Self: Sized, F: FnMut(Self::Item) -> Option<T> { ... } fn take(self, n: usize) -> Take<Self> where Self: Sized { ... } fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P> where Self: Sized, P: FnMut(&Self::Item) -> bool { ... } fn skip(self, n: usize) -> Skip<Self> where Self: Sized { ... } fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P> where Self: Sized, P: FnMut(&Self::Item) -> bool { ... } fn enumerate(self) -> Enumerate<Self> where Self: Sized { ... } fn fuse(self) -> Fuse<Self> where Self: Sized { ... } fn inspect<F>(self, f: F) -> Inspect<Self, F> where Self: Sized, F: FnMut(&Self::Item) { ... } fn buffered(self, n: usize) -> Buffered<Self> where Self: Sized, Self::Item: Future { ... } fn buffer_unordered(self, n: usize) -> BufferUnordered<Self> where Self: Sized, Self::Item: Future { ... } fn collect<C>(self) -> Collect<Self, C> where Self: Sized, C: Default + Extend<Self::Item> { ... } fn chunks(self, size: usize) -> Chunks<Self> where Self: Sized { ... } fn ready_chunks(self, size: usize) -> ReadyChunks<Self> where Self: Sized { ... } fn fold<Acc, F>(self, init: Acc, f: F) -> Fold<Self, F, Acc> where Self: Sized, F: FnMut(Acc, Self::Item) -> Acc { ... } fn for_each<F>(self, f: F) -> ForEach<Self, F> where Self: Sized, F: FnMut(Self::Item) { ... } fn for_each_async<F, Fut>(self, f: F) -> ForEachAsync<Self, F, Fut> where Self: Sized, F: FnMut(Self::Item) -> Fut, Fut: Future<Output = ()> { ... } fn count(self) -> Count<Self> where Self: Sized { ... } fn any<P>(self, predicate: P) -> Any<Self, P> where Self: Sized, P: FnMut(&Self::Item) -> bool { ... } fn all<P>(self, predicate: P) -> All<Self, P> where Self: Sized, P: FnMut(&Self::Item) -> bool { ... } fn try_collect<T, E, C>(self) -> TryCollect<Self, C> where Self: Stream<Item = Result<T, E>> + Sized, C: Default + Extend<T> { ... } fn try_fold<T, E, Acc, F>(self, init: Acc, f: F) -> TryFold<Self, F, Acc> where Self: Stream<Item = Result<T, E>> + Sized, F: FnMut(Acc, T) -> Result<Acc, E> { ... } fn try_for_each<F, E>(self, f: F) -> TryForEach<Self, F> where Self: Sized, F: FnMut(Self::Item) -> Result<(), E> { ... } fn scan<St, B, F>(self, initial_state: St, f: F) -> Scan<Self, St, F> where Self: Sized, F: FnMut(&mut St, Self::Item) -> Option<B> { ... } fn peekable(self) -> Peekable<Self> where Self: Sized { ... } fn throttle(self, period: Duration) -> Throttle<Self> where Self: Sized { ... } fn debounce(self, period: Duration) -> Debounce<Self> where Self: Sized, Self::Item: Unpin { ... }
}
Expand description

Extension trait providing combinator methods for streams.

This trait is automatically implemented for all types that implement Stream.

Provided Methods§

Source

fn next(&mut self) -> Next<'_, Self>
where Self: Unpin,

Returns the next item from the stream.

Source

fn map<T, F>(self, f: F) -> Map<Self, F>
where Self: Sized, F: FnMut(Self::Item) -> T,

Transforms each item using a closure.

Source

fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F>
where Self: Sized, F: FnMut(Self::Item) -> Fut, Fut: Future,

Transforms each item using an async closure.

Source

fn chain<S2>(self, other: S2) -> Chain<Self, S2>
where Self: Sized, S2: Stream<Item = Self::Item>,

Chains this stream with another stream.

Source

fn merge(self, other: Self) -> Merge<Self>
where Self: Sized,

Interleaves this stream with another stream of the same concrete type.

For heterogeneous stream types, use chain, zip, or the free merge function with an iterator of streams.

Source

fn zip<S2>(self, other: S2) -> Zip<Self, S2>
where Self: Sized, S2: Stream,

Zips this stream with another stream, yielding pairs.

Source

fn filter<P>(self, predicate: P) -> Filter<Self, P>
where Self: Sized, P: FnMut(&Self::Item) -> bool,

Yields only items that match the predicate.

Source

fn filter_map<T, F>(self, f: F) -> FilterMap<Self, F>
where Self: Sized, F: FnMut(Self::Item) -> Option<T>,

Filters and transforms items in one step.

Source

fn take(self, n: usize) -> Take<Self>
where Self: Sized,

Takes the first n items.

Source

fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P>
where Self: Sized, P: FnMut(&Self::Item) -> bool,

Takes items while the predicate is true.

Source

fn skip(self, n: usize) -> Skip<Self>
where Self: Sized,

Skips the first n items.

Source

fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P>
where Self: Sized, P: FnMut(&Self::Item) -> bool,

Skips items while the predicate is true.

Source

fn enumerate(self) -> Enumerate<Self>
where Self: Sized,

Enumerates items with their index.

Source

fn fuse(self) -> Fuse<Self>
where Self: Sized,

Fuses the stream to handle None gracefully.

Source

fn inspect<F>(self, f: F) -> Inspect<Self, F>
where Self: Sized, F: FnMut(&Self::Item),

Inspects items without modifying the stream.

Source

fn buffered(self, n: usize) -> Buffered<Self>
where Self: Sized, Self::Item: Future,

Buffers up to n futures, preserving output order.

Source

fn buffer_unordered(self, n: usize) -> BufferUnordered<Self>
where Self: Sized, Self::Item: Future,

Buffers up to n futures, yielding results as they complete.

Source

fn collect<C>(self) -> Collect<Self, C>
where Self: Sized, C: Default + Extend<Self::Item>,

Collects all items into a collection.

Source

fn chunks(self, size: usize) -> Chunks<Self>
where Self: Sized,

Collects items into fixed-size chunks.

Source

fn ready_chunks(self, size: usize) -> ReadyChunks<Self>
where Self: Sized,

Yields immediately available items up to a maximum chunk size.

Source

fn fold<Acc, F>(self, init: Acc, f: F) -> Fold<Self, F, Acc>
where Self: Sized, F: FnMut(Acc, Self::Item) -> Acc,

Folds all items into a single value.

Source

fn for_each<F>(self, f: F) -> ForEach<Self, F>
where Self: Sized, F: FnMut(Self::Item),

Executes a closure for each item.

Source

fn for_each_async<F, Fut>(self, f: F) -> ForEachAsync<Self, F, Fut>
where Self: Sized, F: FnMut(Self::Item) -> Fut, Fut: Future<Output = ()>,

Executes an async closure for each item.

Source

fn count(self) -> Count<Self>
where Self: Sized,

Counts the number of items in the stream.

Source

fn any<P>(self, predicate: P) -> Any<Self, P>
where Self: Sized, P: FnMut(&Self::Item) -> bool,

Checks if any item matches the predicate.

Source

fn all<P>(self, predicate: P) -> All<Self, P>
where Self: Sized, P: FnMut(&Self::Item) -> bool,

Checks if all items match the predicate.

Source

fn try_collect<T, E, C>(self) -> TryCollect<Self, C>
where Self: Stream<Item = Result<T, E>> + Sized, C: Default + Extend<T>,

Collects items from a stream of Results, short-circuiting on error.

Source

fn try_fold<T, E, Acc, F>(self, init: Acc, f: F) -> TryFold<Self, F, Acc>
where Self: Stream<Item = Result<T, E>> + Sized, F: FnMut(Acc, T) -> Result<Acc, E>,

Folds a stream of Results, short-circuiting on error.

Source

fn try_for_each<F, E>(self, f: F) -> TryForEach<Self, F>
where Self: Sized, F: FnMut(Self::Item) -> Result<(), E>,

Executes a fallible closure for each item, short-circuiting on error.

Source

fn scan<St, B, F>(self, initial_state: St, f: F) -> Scan<Self, St, F>
where Self: Sized, F: FnMut(&mut St, Self::Item) -> Option<B>,

Yields intermediate accumulator values, like Iterator::scan.

For each item, calls f(&mut state, item). If f returns Some(value), the value is yielded. If f returns None, the stream terminates.

Source

fn peekable(self) -> Peekable<Self>
where Self: Sized,

Creates a peekable stream that supports looking at the next item without consuming it.

Source

fn throttle(self, period: Duration) -> Throttle<Self>
where Self: Sized,

Rate-limits the stream to at most one item per period.

The first item passes through immediately. Subsequent items that arrive within the suppression window are dropped.

Source

fn debounce(self, period: Duration) -> Debounce<Self>
where Self: Sized, Self::Item: Unpin,

Debounces the stream, emitting only after a quiet period.

When items arrive, they are buffered. If no new item arrives for period, the most recent item is yielded. When the underlying stream ends, any buffered item is flushed immediately.

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 + ?Sized> StreamExt for S