Crates.io | sink-splitter |
lib.rs | sink-splitter |
version | 0.1.0 |
source | src |
created_at | 2017-12-01 22:56:37.533467 |
updated_at | 2017-12-01 22:56:37.533467 |
description | An input Sink that routes each item to one of many output sinks |
homepage | |
repository | https://github.com/paulkernfeld/sink-splitter |
max_upload_size | |
id | 41273 |
size | 12,318 |
An input Sink that routes each item to one of many output sinks.
Insert your output sink before you start sending items for it.
Items are delivered in order. If the output sink corresponding to the current key blocks, then
the Splitter
will also block.
extern crate futures;
extern crate sink_splitter;
use futures::{Future, Sink, Stream};
use futures::stream::iter_ok;
fn main() {
let source = iter_ok::<_, sink_splitter::Error<_, _, _>>(
vec![("left", 1), ("right", 2), ("right", 3), ("left", 4)],
);
let destination_left = Vec::new();
let destination_right = Vec::new();
let (splitter, mut controller) = sink_splitter::new();
controller.insert_sink("left", destination_left).unwrap();
controller.insert_sink("right", destination_right).unwrap();
let (_, splitter) = source.forward(splitter).wait().unwrap();
let sinks = splitter.into_sinks();
assert_eq!(sinks.get("left").unwrap(), &vec![1, 4]);
assert_eq!(sinks.get("right").unwrap(), &vec![2, 3]);
}
License: MIT/Apache-2.0