Created
May 20, 2017 17:09
-
-
Save Nercury/09b99945e32fc96c6edcad3f176dd69e to your computer and use it in GitHub Desktop.
Futures mpsc SendError
This file contains hidden or 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
error[E0277]: the trait bound `futures::sync::mpsc::SendError<{integer}>: std::convert::From<{integer}>` is not satisfied | |
--> lib.rs:102:34 | |
| | |
102 | tx.send_all(input_values.from_err()).wait().expect("send fail"); | |
| ^^^^^^^^ the trait `std::convert::From<{integer}>` is not implemented for `futures::sync::mpsc::SendError<{integer}>` | |
error[E0277]: the trait bound `futures::sync::mpsc::SendError<{integer}>: std::convert::From<{integer}>` is not satisfied | |
--> lib.rs:102:12 | |
| | |
102 | tx.send_all(input_values.from_err()).wait().expect("send fail"); | |
| ^^^^^^^^ the trait `std::convert::From<{integer}>` is not implemented for `futures::sync::mpsc::SendError<{integer}>` | |
| |
This file contains hidden or 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
use futures::{Future, Stream, Sink}; | |
use tokio_core::reactor::Core; | |
use tokio_timer::Timer; | |
use std::time::Duration; | |
use futures::sync::mpsc; | |
let timer = Timer::default(); | |
let input_values = futures::stream::iter((0..6).map(Result::Ok)) | |
.and_then( | |
|v| timer.sleep(Duration::from_secs(v as u64)) | |
.map_err(|_| 3) // trying to set error to () and get rid of TimerError | |
.then(move |res| res.map(|_| v)) | |
); | |
let (tx, rx) = mpsc::channel(30); | |
// How do I convert from () errror to SendError? | |
tx.send_all(input_values.from_err()).wait().expect("send fail"); | |
// Attempt #2 | |
// Note I can't create SendError, because it's | |
// private: https://github.com/alexcrichton/futures-rs/blob/master/src/sync/mpsc/mod.rs#L140 | |
// error: tuple struct `SendError` is private | |
// tx.send_all(input_values.map_err(|e| mpsc::SendError(e))).wait().expect("send fail"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment