From 458ad98fff15b0efcf486364c9553c41a8eb3653 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Sun, 24 Dec 2017 18:32:27 -0600 Subject: [PATCH] Illustrating rust-lang/rfcs#2261 --- cargo.out | 24 +++++++++++++++--------- src/main.rs | 30 ++++++++++++++++++++++++++---- 2 files changed, 41 insertions(+), 13 deletions(-) diff --git a/cargo.out b/cargo.out index 707e180..563adea 100644 --- a/cargo.out +++ b/cargo.out @@ -1,14 +1,20 @@ - Compiling futuretest v0.1.0 (file:///mnt/c/Users/Mahmoud/git/futuretest) -error[E0277]: the trait bound `(): futures::Future` is not satisfied - --> src/main.rs:17:1 + Compiling futuretest v0.1.0 (file:///mnt/d/GIT/futuretest) +error[E0308]: match arms have incompatible types + --> src/main.rs:21:13 | -17 | / fn test() -> MapErr<(), ()> { -18 | | future::ok(()) -19 | | .map_err(|String| ()) -20 | | } - | |_^ the trait `futures::Future` is not implemented for `()` +21 | / match err { +22 | | ErrorCode::Case1 => case1(), +23 | | ErrorCode::Case2 => case2(), +24 | | } + | |_____________^ expected anonymized type, found a different anonymized type | - = note: required by `futures::MapErr` + = note: expected type `impl futures::Future` (anonymized type) + found type `impl futures::Future` (anonymized type) +note: match arm with an incompatible type + --> src/main.rs:23:37 + | +23 | ErrorCode::Case2 => case2(), + | ^^^^^^^ error: aborting due to previous error diff --git a/src/main.rs b/src/main.rs index 767c803..695234e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,15 +6,37 @@ use futures::future::{self}; use futures::future::*; use tokio_core::reactor::Core; +enum ErrorCode +{ + Case1, + Case2, +} + fn main() { let mut core = Core::new().expect("Failed to initialize tokio_core reactor!"); - let f = test(); + let f = async_entry_point() + .or_else(move |err| { + //the problem is that the three matches below resolve to different anonymized types + match err { + ErrorCode::Case1 => case1(), + ErrorCode::Case2 => case2(), + } + }) + ; - core.run(f).unwrap(); + core.run(f); +} + +fn async_entry_point() -> impl Future { + future::ok(()) } -fn test() -> MapErr<(), ()> { +fn case1() -> impl Future { future::ok(()) - .map_err(|String| ()) } + +fn case2() -> impl Future { + future::ok(()) +} +