Here's an example:
#[tokio::main]
async fn main() {
let args: Vec<String> = env::args().collect();
let body = get_pokemon(&args[1]).await;
// here
let pokemon = parse_response(body);
}
struct Pokemon {}
async fn get_pokemon(pokemon: &String) -> reqwest::Result<String> {
let body = reqwest::get(format!("https://pokeapi.co/api/v2/pokemon/{}", pokemon))
.await?
.text()
.await?;
Ok(body)
}
async fn parse_response(response: String) -> Pokemon {}
body
is of type Result<String, Error>
, is there a way to match what the get_pokemon function returns with the match
keyword or something similar? i.e. if it returns an error then do this, if a String, do this, etc.