I would like to call two functions that perform an HTTP call with reqwest on two different branches of a match:
async fn list_projects() -> Result<(), reqwest::Error> {
let body = reqwest::get("https://...")
.await?
.text()
.await?;
println!("{:?}", body);
Ok(())
}
async fn list_categories() -> Result<(), reqwest::Error> {
let body = reqwest::get("http://...")
.await?
.text()
.await?;
println!("{:?}", body);
Ok(())
}
match &args.list {
List::projects => list_projects(),
List::categories => list_categories()
}
I get the following error:
async fn list_categories() -> Result<(), reqwest::Error> {
| -------------------------- the `Output` of this `async fn`'s found opaque type
...
49 | / match &args.list {
50 | | List::projects => list_projects(),
| | --------------- this is found to be of type `impl std::future::Future`
51 | | List::categories => list_categories()
| | ^^^^^^^^^^^^^^^^^ expected opaque type, found a different opaque type
52 | | }
| |_____- `match` arms have incompatible types
|
= note: expected type `impl std::future::Future` (opaque type at <src/main.rs:29:29>)
found opaque type `impl std::future::Future` (opaque type at <src/main.rs:38:31>)
= note: distinct uses of `impl Trait` result in different opaque types
= help: if both `Future`s have the same `Output` type, consider `.await`ing on both of them
Should I use std::future::Either
?