Crate stream_partition

Crate stream_partition 

Source
Expand description

Stream partitioning utilities for splitting a single stream into multiple streams based on keys.

This module provides functionality to partition a stream into multiple sub-streams, where each sub-stream contains only items that match a specific key determined by an async function.

§Example

use futures::{stream, StreamExt};
use futures::future::ready;
use stream_partition::StreamPartitionExt;

let stream = stream::iter(vec![1, 2, 3, 4, 5, 6]);
let mut partitioner = stream.partition_by(|x| ready(x % 2));

// Get odd numbers
let mut odd_stream = partitioner.lock().unwrap().get_partition(1);
let first_odd = odd_stream.next().await.unwrap();
assert_eq!(first_odd, 1);

Structs§

PartitionBy
A stream that partitions items from an underlying stream into multiple sub-streams based on keys generated by an async function.
Partitioned
A sub-stream that yields only items matching a specific key from the partitioned stream.

Traits§

StreamPartitionExt
Extension trait that adds partitioning functionality to any stream.