Consideriamo i seguenti esempi:
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"
Sto chiedendo dell'espressione |x| async move {}invece di async move |x| {}. Quest'ultimo è più ovvio, ma si imbatte nell'errore di compilazione:
error[E0658]: async closures are unstable
Quindi mi chiedo, qual è la differenza tra async move || {}e || async move {}. Entrambi sembrano essere chiusure per l'utilizzo della moveparola chiave.
$ rustc --version
rustc 1.39.0 (4560ea788 2019-11-04)