#future #monads #do

mdo-future

Zero-cost futures support for rust-mdo

2 unstable releases

Uses old Rust 2015

0.2.0 Feb 27, 2017
0.1.0 Feb 9, 2017

#9 in #do

WTFPL license

7KB
143 lines

rust-mdo-future

Rust-mdo-future is a small crate that enables future support in mdo

Just take a look:

#[macro_use] extern crate mdo;
extern crate mdo-future;

use futures::Future;
use futures::future::ok;
use futures_cpupool::CpuPool;
use mdo-future::future::{bind, ret};

//....
// Somewhere in code

let pool = CpuPool::new_num_cpus();

let get_num = ok::<u32, String>(42);
let get_factor = ok::<u32, String>(2);

let res = mdo! {
    arg =<< get_num;
    fact =<< get_factor;
    ret ret(arg * fact)
};

let val = pool.spawn(res);

assert_eq!(val.wait().unwrap(), 84);

//....

Dependencies

~53KB