0

I am trying to fetch web data in rust by utilizing the reqwest library. I have created the project with Cargo However, whenever I try to compile the code I am getting an error:

7 |     let mut response = reqwest::get(url).status();
  |                                          ^^^^^^ method not found in `impl std::future::Future`

It seems like a simple error--maybe I'm just forgetting about some syntax somewhere. I don't know why it keeps referring to that standard library.

extern crate reqwest;
extern crate select;
extern crate scraper;
extern crate tokio;

fn get_website(url: &str) {
    let mut response = reqwest::get(url).status();

    //print!("{:?}\n", response.status());
}

fn main() {
    let url = "https://google.com";

    get_website(&url);
}

my Cargo.toml file dependencies looks like:

[dependencies] 
reqwest = "0.10.4" 
select = "0.4.3" 
scraper = "0.12.0" 
tokio = {version = "0.2.21", features = ["full"]}
winsticknova
  • 365
  • 2
  • 5
  • 17
  • 1
    The latest versions of reqwest return a `Future`, so you need to handle it before retrieving the outcome. – E_net4 May 24 '20 at 09:05
  • 1
    The linked answer is a basic template you can use. you only need to return the `status` instead of the `text`. The error is informing you that `get` returns a `Future` and that the future doesn't have a `status` method on it. The `Response` that's returned after `await`ing the future has it. – Dimitris Fasarakis Hilliard May 24 '20 at 09:22
  • this makes a lot more sense. I didn't realize that in the new versions it was handled this way. I must have been looking at old examples. – winsticknova May 24 '20 at 09:33

0 Answers0