Skip to content

Instantly share code, notes, and snippets.

@MindFlavor
Last active July 8, 2017 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MindFlavor/85c89f0ed3b9174860f281e3737d4b96 to your computer and use it in GitHub Desktop.
Save MindFlavor/85c89f0ed3b9174860f281e3737d4b96 to your computer and use it in GitHub Desktop.
#![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