2017-12-13 09:34:46 -06:00
|
|
|
#![feature(conservative_impl_trait)]
|
|
|
|
|
2017-12-09 12:50:50 -06:00
|
|
|
extern crate futures;
|
|
|
|
extern crate tokio_core;
|
2017-12-24 18:57:00 -06:00
|
|
|
use futures::future::{self, FutureResult};
|
2017-12-09 12:50:50 -06:00
|
|
|
use futures::future::*;
|
|
|
|
use tokio_core::reactor::Core;
|
|
|
|
|
2017-12-24 18:57:00 -06:00
|
|
|
#[derive(Debug)]
|
|
|
|
enum ErrorCode
|
|
|
|
{
|
|
|
|
CanHandleWithAsync,
|
|
|
|
CanHandleWithSync,
|
|
|
|
CannotHandle
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
enum ErrorCode2
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-12-09 12:50:50 -06:00
|
|
|
fn main() {
|
|
|
|
let mut core = Core::new().expect("Failed to initialize tokio_core reactor!");
|
|
|
|
|
2017-12-24 18:57:00 -06:00
|
|
|
let f = async_entry_point()
|
|
|
|
.or_else(move |err| {
|
|
|
|
//the problem is that the three matches below resolve to different future types
|
|
|
|
match err {
|
|
|
|
ErrorCode::CanHandleWithAsync => async_error_handler()
|
|
|
|
.map_err(|_| ErrorCode::CannotHandle).wait(),
|
|
|
|
ErrorCode::CanHandleWithSync => future::result(sync_error_handler()),
|
|
|
|
ErrorCode::CannotHandle => future::err(ErrorCode::CannotHandle),
|
|
|
|
}
|
|
|
|
})
|
|
|
|
;
|
2017-12-09 12:50:50 -06:00
|
|
|
|
|
|
|
core.run(f).unwrap();
|
|
|
|
}
|
2017-12-13 09:34:46 -06:00
|
|
|
|
2017-12-24 18:57:00 -06:00
|
|
|
fn async_entry_point() -> FutureResult<(), ErrorCode> {
|
|
|
|
future::ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn async_error_handler() -> FutureResult<(), ErrorCode2> {
|
2017-12-13 09:34:46 -06:00
|
|
|
future::ok(())
|
|
|
|
}
|
2017-12-24 18:57:00 -06:00
|
|
|
|
|
|
|
fn sync_error_handler() -> Result<(), ErrorCode> {
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|