A future is work waiting to be driven.
Distinguish constructing asynchronous work from executing it.
01 Understand the contract
An async function returns a future: a state machine representing work that can make progress when polled. Calling it alone does not run the body to completion. await suspends the current future while another future is pending; it does not inherently spawn a thread. An executor such as Tokio polls ready tasks, while reactor infrastructure wakes work when I/O becomes ready. Use the cookbook’s Tokio/Axum projects to run async I/O. This standard-library example deliberately creates and drops a future to make laziness visible.
02 Make it concrete
This is a complete standard-library example. Use Rust stable with the 2024 edition. Run it locally using the Rust workbench.
async fn compute() -> u32 {
println!("body ran");
42
}
fn main() {
let work = compute();
println!("future created");
drop(work);
println!("future dropped without polling");
}future created future dropped without polling
- 1
Calling compute constructs a future.
- 2
No executor polls the future here, so its body does not print.
- 3
The server cookbook uses #[tokio::main] to supply a runtime.
cargo run -p lesson_async_futures03 Mind the boundary
04 Your next build
Create an async function returning a String, then show that constructing its future does not execute its body.
Reveal one possible solution +
async fn message() -> String {
"ready".to_owned()
}
fn main() {
let future = message();
drop(future);
}05 Check your reasoning
Does calling an async fn by itself run its body to completion?
Understand it.
Then make it yours.
Run the example, try your own input, and explain the boundary. Log the lesson when the idea makes sense.