稳定的 async fn 和 await

版本新特性 / Rust 1.39

// *** 以前 ***
// 组合子链:步骤的顺序要从里向外读
fn load(id: u32) -> impl Future<Item = String, Error = Error> {
    fetch_user(id)
        .and_then(|user| fetch_profile(user.profile_id))
        .map(|profile| profile.name)
}

// *** 在 1.39 版本中 ***
// 同样的步骤,写成普通的顺序代码
async fn load(id: u32) -> Result<String, Error> {
    let user = fetch_user(id).await?;
    let profile = fetch_profile(user.profile_id).await?;
    Ok(profile.name)
}