Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Code shared from the Rust Playground
extern crate futures;
use futures::stream::Stream;
use futures::TryStreamExt;
use futures::{Sink, SinkExt};
// We take a <u64, u32> stream+sink and want to convert it to <u128, u64>
pub fn convert_sink_stream(
connection: impl Stream<Item = Result<u64, u32>> + Sink<u64, Error = u32>,
) -> impl Stream<Item = Result<u128, u64>> + Sink<u128, Error = u64>
{
connection
.err_into::<u64>()
.sink_err_into::<u64>()
.map_ok(|x|u128::from(x))
.with(|x| {
let y = u128::from(x);
futures::future::ok(y)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.