Lesson 33 of 50 · rust
Async Programming Basics
Duration: 20 minutes
Lesson 33 of 50 · rust
Duration: 20 minutes
async fn to define asynchronous functions.\n\nrust\nasync fn fetch_data() -> Result<String, reqwest::Error> {\n let response = reqwest::get(\"https://api.example.com\").await?;\n let body = response.text().await?;\n Ok(body)\n}\n\n#[tokio::main]\nasync fn main() {\n match fetch_data().await {\n Ok(text) => println!(\"Data: {}\", text),\n Err(e) => eprintln!(\"Error: {}\", e),\n }\n}\n\n