Created
January 14, 2020 14:21
-
-
Save rust-play/9dd7eda74721e7775d6ca2cb80e60745 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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