error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `std::ops::Try`)
--> src/main.rs:6:39
|
6 | let resp: HashMap<String, String> = reqwest::get(url.as_str())?.json()?; // This errors? Why?
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot use the `?` operator in a function that returns `()`
|
= help: the trait `std::ops::Try` is not implemented for `()`
= note: required by `std::ops::Try::from_error`
error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `std::ops::Try`)
--> src/main.rs:6:39
|
6 | let resp: HashMap<String, String> = reqwest::get(url.as_str())?.json()?; // This errors? Why?
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot use the `?` operator in a function that returns `()`
|
= help: the trait `std::ops::Try` is not implemented for `()`
= note: required by `std::ops::Try::from_error`
Note that usage of the ? operator requires that the function returns a Result, because it is a smart unwrapper for results
You can fix this by changing the return type of the function: