Last active
July 8, 2017 14:10
-
-
Save MindFlavor/85c89f0ed3b9174860f281e3737d4b96 to your computer and use it in GitHub Desktop.
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
#![feature(conservative_impl_trait)] | |
extern crate futures; | |
use futures::future::*; | |
#[derive(Debug)] | |
struct ErrorA; | |
#[derive(Debug)] | |
struct ErrorB; | |
impl From<ErrorA> for ErrorB { | |
fn from(a: ErrorA) -> ErrorB { | |
ErrorB {} | |
} | |
} | |
fn met_a() -> Result<(), ErrorA> { | |
Ok(()) | |
} | |
fn met_b() -> Result<(), ErrorB> { | |
met_a()?; | |
Ok(()) | |
} | |
fn io_a() -> impl Future<Item = (), Error = ErrorA> { | |
ok(()) | |
} | |
fn io_b() -> impl Future<Item = (), Error = ErrorB> { | |
ok(()) | |
} | |
fn code() -> impl Future<Item = (), Error = ErrorB> { | |
io_a() | |
.from_err() | |
.and_then(|_| { | |
ok({ | |
met_a()?; | |
met_b()?; | |
}) | |
}) | |
.from_err() | |
.and_then(|_| done(met_b()).and_then(|_| io_b())) | |
} | |
fn main() { | |
let future = code(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment