I'm trying to replicate an example from reqwest documentation. Here is the example:
let body = reqwest::get("https://www.rust-lang.org")?
.text()?;
After I have added the reqwest = "0.10.10"
line in the file Cargo.toml, I add the following code in my main.rs
file:
extern crate reqwest;
fn main() {
let body = reqwest::get("https://www.rust-lang.org")?.text()?;
println!("body = {:?}", body);
}
This code don't compile and returns the following error:
cannot use the `?` operator in a function that returns `()`
I'm a bit surprised with this behaviour since my code is almost ipsis litteris the documentation code.
I think that ?
works only on Response objects, so I checked which object the get
method is returning:
extern crate reqwest;
fn print_type_of<T>(_: &T) {
println!("{}", std::any::type_name::<T>())
}
fn main() {
let body = reqwest::get("https://www.rust-lang.org");
print_type_of(&body);
}
output:
core::future::from_generator::GenFuture<reqwest::get<&str>::{{closure}}
I mean, why I'm not getting an Response object instead, just like the documentation?