Skip to main content

Stream

Trait Stream 

Source
pub trait Stream: StreamSource + Sized {
    // Provided methods
    fn map<U, F>(self, f: F) -> MapStream<Self, F>
       where F: FnMut(Self::Item) -> U { ... }
    fn filter<P>(self, pred: P) -> FilterStream<Self, P>
       where P: FnMut(&Self::Item) -> bool { ... }
    fn take(self, n: usize) -> TakeStream<Self> { ... }
    fn skip(self, n: usize) -> SkipStream<Self> { ... }
    fn flatten(self) -> FlattenStream<Self>
       where Self::Item: IntoIterator { ... }
    fn by_ref(&mut self) -> ByRefStream<'_, Self> { ... }
    fn collect_stream(self) -> Vec<Self::Item> { ... }
    fn count_stream(self) -> usize { ... }
    fn for_each_stream<F: FnMut(Self::Item)>(self, f: F) { ... }
}
Expand description

Full stream combinator trait.

Automatically implemented for any T: StreamSource + Sized. Provides the ergonomic adaptor API (map, filter, take, etc.).

For boxed, type-erased streams use StreamSource directly or wrap in BoxedStream.

Provided Methods§

Source

fn map<U, F>(self, f: F) -> MapStream<Self, F>
where F: FnMut(Self::Item) -> U,

Apply f to each item, producing a new stream.

Source

fn filter<P>(self, pred: P) -> FilterStream<Self, P>
where P: FnMut(&Self::Item) -> bool,

Keep only items for which pred returns true.

Source

fn take(self, n: usize) -> TakeStream<Self>

Take at most n items then stop.

Source

fn skip(self, n: usize) -> SkipStream<Self>

Skip the first n items then yield the rest.

Source

fn flatten(self) -> FlattenStream<Self>
where Self::Item: IntoIterator,

Flatten a stream of iterables into a flat stream.

Source

fn by_ref(&mut self) -> ByRefStream<'_, Self>

Borrow this stream mutably, producing an adaptor that forwards to it.

Source

fn collect_stream(self) -> Vec<Self::Item>

Collect all remaining items into a Vec.

Source

fn count_stream(self) -> usize

Count remaining items (exhausts the stream).

Source

fn for_each_stream<F: FnMut(Self::Item)>(self, f: F)

Apply f to each item for its side-effects.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§