How does async await work in Rust

Async/await in Rust enables non-blocking code by pausing execution at .await points until asynchronous tasks complete.

Async/await in Rust allows you to write non-blocking code that looks synchronous by pausing execution at .await until a future completes. You define an async fn to return a future, then chain .await on operations like trpl::get(url) to wait for the result without blocking the thread.

use trpl::Html;

async fn page_title(url: &str) -> Option<String> {
    let response_text = trpl::get(url).await.text().await;
    Html::parse(&response_text)
        .select_first("title")
        .map(|title| title.inner_html())
}