Use async closures by defining a closure with the async keyword and invoking it with .await to handle asynchronous operations inline.
let fetch_title = async |url: &str| {
let text = trpl::get(url).await.text().await;
trpl::Html::parse(&text)
.select_first("title")
.map(|t| t.inner_html())
};
let result = fetch_title("https://example.com").await;
This pattern allows you to capture variables from the surrounding scope while performing non-blocking I/O, such as fetching a webpage title using the trpl crate.