expression

Async move block: capture owned inputs

An async move block takes captured values by value. For a String that means transferring ownership into the future, making it useful when the computation outlives the original variable scope. Moving references into a future does not extend their referents’ lifetimes. Expected stdout (not executed): Ready(6) Common mistake: Assuming async move makes every captured reference static.

Formal Syntax & Structure

rust syntaxrust
let f = async move { ... };

Working Example

Example Snippetrust
fn main() {    use std::{future::Future, task::{Context, Poll, Wake, Waker}, sync::Arc};    struct Noop;    impl Wake for Noop { fn wake(self: Arc<Self>) {} }    let w = Waker::from(Arc::new(Noop));    let mut cx = Context::from_waker(&w);    let f = {        let label = String::from("report");        async move { label.len() }    };    let mut f = std::pin::pin!(f);    println!("{:?}", f.as_mut().poll(&mut cx));}
Rust Reference