Hi! I'm very new to Rust, apologies if this looks lame. I found this example in Reqwest::blocking documentation Client in reqwest::blocking - Rust :
use reqwest::blocking::Client;
let client = Client::new();
let resp = client.get("http://httpbin.org/").send()?;
But when I copy almost identical I get the following compilation error:
error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`)
--> src/main.rs:10:13
|
5 | / fn main() {
6 | | let client = Client::new();
7 | |
8 | | let response = client.get(
9 | | "https://httpbin.org"
10 | | ).send()?;
| | ^ cannot use the `?` operator in a function that returns `()`
11 | | println!("{:?}",response);
12 | | }
| |_- this function should return `Result` or `Option` to accept `?`
|
= help: the trait `FromResidual<Result<Infallible, reqwest::Error>>` is not implemented for `()`
I've checked and it is reqwest v0.11.12 for both the documentation and my installed version.
Is this an error in the docs? AFAIK the examples are used as tests when compiling the crate so this shouldn't pass... I would be happy to raise de issue on github but I feel that I'm missing something here...
My full code:
use reqwest::blocking::Client;
use std::collections::HashMap;
fn main() {
let client = Client::new();
let response = client.get(
"https://httpbin.org"
).send()?;
println!("{:?}",response);
}
Cargo.toml
[package]
name = "harvester_siem"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
reqwest = { version = "0.11.12", features = ["blocking", "json"] }