I am trying to use the reqwest::blocking
example, and I am encountering an error.
Firstly,
"the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `std::ops::Try`)
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`
when using the following code:
use reqwest;
fn main() {
let body = reqwest::blocking::get("https://www.rust-lang.org")?
.text()?;
println!("body = {:?}", body);
}
After removing the ?
s from the code:
no method named `text` found for enum `std::result::Result<reqwest::blocking::Response, reqwest::Error>` in the current scope
method not found in `std::result::Result<reqwest::blocking::Response, reqwest::Error>`
use reqwest;
fn main() {
let body = reqwest::blocking::get("https://www.rust-lang.org")
.text();
println!("body = {:?}", body);
}
I have enabled the blocking feature in my cargo.toml:
[dependencies]
reqwest = {version = "0.11.3", features = ["blocking"]}
I was able to find an issue that is very similar to my problem, however it is now closed and locked. If there are any relevant details that I failed to mention, please tell me.