How to Use Async Iterators (Streams) in Rust

Define async functions with the `async` keyword and use `await` to pause execution until the result is ready.

Use the async keyword to define a function that returns a Future and await to pause execution until the result is ready.

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())
}

This pattern allows you to chain asynchronous operations like fetching a URL and parsing HTML without blocking the thread.