【发布时间】:2020-03-28 02:27:00
【问题描述】:
让我们考虑以下示例:
main.rs
use futures::executor::block_on;
use futures::future::{FutureExt, TryFutureExt};
async fn fut1() -> Result<String, u32> {
Ok("ok".to_string())
}
fn main() {
println!("Hello, world!");
match block_on(fut1().and_then(|x| async move { Ok(format!("{} is \"ok\"", x)) })) {
Ok(s) => println!("{}", s),
Err(u) => println!("{}", u)
};
}
Cargo.toml
[dependencies]
futures = "^0.3"
我问的是表达式|x| async move {} 而不是async move |x| {}。后者比较明显,但是会遇到编译错误:
error[E0658]: async closures are unstable
那我想知道async move || {}和|| async move {}有什么区别。它们似乎都是使用 move 关键字的闭包。
$ rustc --version
rustc 1.39.0 (4560ea788 2019-11-04)
【问题讨论】:
标签: rust