Use async functions and the await keyword to handle non-blocking operations like network requests in Rust.
Use the async keyword to define a function that returns a Future and the await keyword to suspend execution until that future completes.
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())
}
Async functions let your program start a task and move on to other work instead of waiting for it to finish. You use await to pause that specific task only when you actually need the result. It's like ordering food at a restaurant: you place the order and chat with friends while waiting, rather than staring at the kitchen until the food is ready.