pub trait SplitStreamByExt<P>: Stream {
// Provided methods
fn split_by(
self,
predicate: P,
) -> (TrueSplitBy<Self::Item, Self, P>, FalseSplitBy<Self::Item, Self, P>)
where P: Fn(&Self::Item) -> bool,
Self: Sized { ... }
fn split_by_buffered<const N: usize>(
self,
predicate: P,
) -> (TrueSplitByBuffered<Self::Item, Self, P, N>, FalseSplitByBuffered<Self::Item, Self, P, N>)
where P: Fn(&Self::Item) -> bool,
Self: Sized { ... }
}
Expand description
This extension trait provides the functionality for splitting a
stream by a predicate of type Fn(&Self::Item) -> bool
. The two resulting
streams will both yield Self::Item
Provided Methods§
Sourcefn split_by(
self,
predicate: P,
) -> (TrueSplitBy<Self::Item, Self, P>, FalseSplitBy<Self::Item, Self, P>)
fn split_by( self, predicate: P, ) -> (TrueSplitBy<Self::Item, Self, P>, FalseSplitBy<Self::Item, Self, P>)
This takes ownership of a stream and returns two streams based on a
predicate. When the predicate returns true
, the item will appear in
the first of the pair of streams returned. Items that return false will
go into the second of the pair of streams
use split_stream_by::SplitStreamByExt;
let incoming_stream = futures::stream::iter([0,1,2,3,4,5]);
let (even_stream, odd_stream) = incoming_stream.split_by(|&n| n % 2 == 0);
Sourcefn split_by_buffered<const N: usize>(
self,
predicate: P,
) -> (TrueSplitByBuffered<Self::Item, Self, P, N>, FalseSplitByBuffered<Self::Item, Self, P, N>)
fn split_by_buffered<const N: usize>( self, predicate: P, ) -> (TrueSplitByBuffered<Self::Item, Self, P, N>, FalseSplitByBuffered<Self::Item, Self, P, N>)
This takes ownership of a stream and returns two streams based on a
predicate. When the predicate returns true
, the item will appear in
the first of the pair of streams returned. Items that return false will
go into the second of the pair of streams. This will buffer up to N
items of the inactive stream before returning Pending and notifying that
stream
use split_stream_by::SplitStreamByExt;
let incoming_stream = futures::stream::iter([0,1,2,3,4,5]);
let (even_stream, odd_stream) = incoming_stream.split_by_buffered::<3>(|&n| n % 2 == 0);