Async/Await & Tokio in Rust

From the Rust cheat sheet ยท Async Programming ยท verified Jul 2026

Async/Await & Tokio

Write async functions and use the tokio runtime.

rust
// Add to Cargo.toml:
// [dependencies]
// tokio = { version = "1", features = ["full"] }

#[tokio::main]
async fn main() {
    let result = fetch_data().await;
    println!("{result}");
}

async fn fetch_data() -> String {
    // .await pauses until the future completes
    "data".to_string()
}
๐Ÿ’ก async fn returns a Future โ€” nothing happens until you .await it
โšก tokio::join! runs futures concurrently; sequential .await runs them one after another
๐Ÿ“Œ Use tokio::sync::Mutex (not std::sync::Mutex) in async code โ€” it doesn't block the runtime
๐ŸŸข tokio::spawn creates lightweight tasks โ€” much cheaper than OS threads
asyncawaittokiofutures
Back to the full Rust cheat sheet