Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created January 14, 2020 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rust-play/9dd7eda74721e7775d6ca2cb80e60745 to your computer and use it in GitHub Desktop.
Save rust-play/9dd7eda74721e7775d6ca2cb80e60745 to your computer and use it in GitHub Desktop.
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