Rust/async
Rust async
- Here's a clean, Rust-native explanation of the selected line and the constructs involved.
🔍 The selected line
1.
async { ... }— an async block expressionasync { ... }is an expression that returns a future — specifically an anonymous type that implementsFuture<Output = T>.- Inside an async block, you can use
await, but the block itself does not run until something polls the future (usually an executor). - It is similar to:
- Other Rust constructs that work the same way (i.e., block forms that produce values) include:
- Rust's rule: Blocks are expressions that evaluate to the last expression inside.
- So the async block:
2. What is
.await?3. The sequence of evaluation
4. Are there other parts of Rust with similar syntax?
Quick mental model