What Is the Difference Between Threads and Async Tasks in Rust?

Threads are OS-managed concurrent units for CPU work, while async tasks are lightweight, cooperative units for high-concurrency I/O.

Threads are OS-managed execution units that run concurrently on CPU cores, while async tasks are lightweight, user-space units scheduled cooperatively by a runtime like Tokio. Threads block the OS when waiting, whereas async tasks yield control back to the runtime when awaiting I/O, allowing thousands of tasks to run on a single thread. Use threads for CPU-bound work and async tasks for high-concurrency I/O.

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