Rust’s async ecosystem includes powerful libraries like tokio
and async-std
that provide runtime support for async operations. These libraries offer utilities for managing tasks, handling I/O, and more, making it easier to build concurrent applications.
#[tokio::main]
async fn main() {
let urls = vec!["https://example.com", "https://rust-lang.org"];
let futures = urls.into_iter().map(|url| fetch_data(url));
let results: Vec<_> = futures::future::join_all(futures).await;
for result in results {
match result {
Ok(data) => println!("Fetched data: {}", data),
Err(e) => println!("Error fetching data: {}", e),
}
}
}