4

I'm trying to run basic reqwest example:

extern crate reqwest;
extern crate tokio;

#[tokio::main]
async fn main() -> Result<(), reqwest::Error> {
    let res = reqwest::Client::new()
        .get("https://hyper.rs")
        .send()
        .await?;

    println!("Status: {}", res.status());

    let body = res.text().await?;

    println!("Body:\n\n{}", body);

    Ok(())
}

Error that I'm getting:

   --> src/main.rs:6:15
    |
6   |       let res = reqwest::Client::new()
    |  _______________^
7   | |         .get("https://hyper.rs")
8   | |         .send()
9   | |         .await?;
    | |______________^ the trait `std::future::Future` is not implemented for `std::result::Result<reqwest::Response, reqwest::Error>`

Rust version: rustc 1.39.0 (4560ea788 2019-11-04)

Library versions:

reqwest = "0.9.22"
tokio = { version = "0.2.0-alpha.6", features = ["full"] }

Does anybody know what is wrong here?

Ömer Erden
  • 7,680
  • 5
  • 36
  • 45
semanser
  • 2,310
  • 2
  • 15
  • 33

1 Answers1

6

Same problem as here, just in reverse. You are using reqwest-0.9, which is using the blocking interface by default. Update to reqwest-0.10 to get the async interface.

If you can't update to reqwest-0.10, the async interface in reqwest-0.9 is in reqwest::async. E.g. reqwest::async::Client::new(...).

user2722968
  • 13,636
  • 2
  • 46
  • 67
  • Thansk a lot, it helped! In my case, the working combination of `tokio` and `reqwest` are `reqwest = "0.10.0-alpha.2"` and `tokio = { version = "0.2.0-alpha.6" }` – semanser Dec 01 '19 at 13:21