Rust Async Deep Dive

The final chapter of the journey: asynchronous programming.

An async function

async fn fetch(url: &str) -> String {
    // pretend we do IO here
    format!("contents of {url}")
}

Futures are lazy; they do nothing until polled by an executor. 🚀

Never call blocking code inside an async fn — it stalls the entire executor thread[1].

  1. For CPU-bound or blocking work, use spawn_blocking (Tokio) or a dedicated thread pool.