Expand description
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);Structs§
- Router
Sink - A sink capable of routing incoming items to one of two sinks
Enums§
- Route
- Marker to decide which route the item has to take
- Router
Sink Error - Encapsulate errors from both Sinks