试图导入`reqwest :: async`错误,指出`async`是一个保留关键字

问题描述 投票:3回答:1

我想使用reqwest包进行异步HTTP请求。我有以下代码:

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

当我尝试编译我的代码时,我收到以下错误:

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

如何从async模块导入?

syntax rust reqwest rust-2018
1个回答
5
投票

由于reqwest::async创建之前async是一个保留关键字(发生在Rust 2018,我相信)以前这个Just Worked™。

既然async是保留关键字,您需要使用raw identifier语法:

use request::r#async::Client;
© www.soinside.com 2019 - 2024. All rights reserved.