async 块

版本新特性 / Rust 1.39

// *** 以前 ***
// future 值过去由现成的组合子拼装而成
let task = futures::future::ok::<_, Error>(2).map(|x| x * 2);

// *** 在 1.39 版本中 ***
// async 块是产生 future 的表达式
let task = async {
    let x = fetch_number().await?;
    Ok::<_, Error>(x * 2)
};

// async move 取得捕获值的所有权
let name = String::from("prod");
let named = async move {
    println!("{}", name);
};