1 unstable release
Uses old Rust 2015
0.1.0 | Jun 7, 2017 |
---|
#3 in #capable
10KB
151 lines
futures-router-sink
This library allows to combine two sinks into one.
Usage
Add this to your Cargo.toml
:
[dependencies]
futures-router-sink = { git = "https://github.com/Kintaro/futures-router-sink.git" }
extern crate futures_router_sink;
use futures_router_sink::{Route, RouterSink};
License
futures-router-sink
is distributed under the terms of the MIT license.
See LICENSE for details.
lib.rs
:
Router Sink
Example
use futures::{stream, Stream};
use futures_router_sink::{Route, RouterSink, RouterSinkError};
// Create the two sinks that we are going to route into
let even = Vec::<usize>::new();
let odd = Vec::<usize>::new();
// Create the router sink
let router = RouterSink::new(even, odd);
// Some made up data where we route even numbers
// to the left and odd numbers to the right sink
let input = (0..10)
.map(|x| {
if x % 2 == 0 {
Route::Left(x)
} else {
Route::Right(x)
}
})
.map(Ok::<_, ()>)
.collect::<Vec<_>>();
stream::iter(input)
.map_err(|_| RouterSinkError::Left(()))
.forward(router);
Dependencies
~53KB