expression
async move closures: owned captures
The move modifier captures referenced outer values by value; it does not mean every invocation consumes the closure. A call may borrow its owned captures, depending on how they are used. The fixture-only ready_now helper polls once and rejects Pending; it is not an executor. Expected stdout (not executed): 5 5 Common mistake: Assuming move automatically makes each call a once-only call or every returned future static.
Formal Syntax & Structure
rust syntaxrust
let f = async move || { ... };Working Example
Example Snippetrust
fn main() { use std::{future::Future, task::{Context, Poll, Waker}}; fn ready_now<F: Future>(f: F) -> F::Output { let mut f = std::pin::pin!(f); let mut cx = Context::from_waker(Waker::noop()); match f.as_mut().poll(&mut cx) { Poll::Ready(value) => value, Poll::Pending => panic!("fixture expected immediate readiness"), } } let label = String::from("crate"); let f = async move || label.len(); println!("{} {}", ready_now(f()), ready_now(f()));}