4

I want to make asynchronous HTTP requests using the reqwest crate. I have the following code:

// see https://docs.rs/reqwest/*/reqwest/async/index.html
use reqwest::async::Client;

When I attempt to compile my code I get the following error:

error: expected identifier, found reserved keyword `async`
 --> src/main.rs:1:14
  |
1 | use reqwest::async::Client;
  |              ^^^^^ expected identifier, found reserved keyword

How do I import from the async module?

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
taryn
  • 581
  • 8
  • 18

1 Answers1

5

Since reqwest::async was created before async was a reserved keyword (which happened in Rust 2018, I believe) previously this Just Worked™.

Now that async is a reserved keyword you need to use the raw identifier syntax:

use request::r#async::Client;
taryn
  • 581
  • 8
  • 18
  • 2
    You can also "fix" this by not opting in to Edition 2018 in your `Cargo.toml`. 2015 is the default and `asyn` is not reserved there. – Peter Hall Feb 17 '19 at 15:49