特性 `std::future::Future` 没有为 `std::result::Result<reqwest::Response, reqwest::Error>` 实现

The trait `std::future::Future` is not implemented for `std::result::Result<reqwest::Response, reqwest::Error>`

我正在尝试 运行 基本 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(())
}

我得到的错误:

   --> 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>`

铁锈版本:rustc 1.39.0 (4560ea788 2019-11-04)

库版本:

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

有人知道这里出了什么问题吗?

相同的问题,只是相反。您正在使用 reqwest-0.9,它默认使用阻塞接口。更新到 reqwest-0.10 以获取异步接口。

如果您无法更新到 reqwest-0.10reqwest-0.9 中的异步接口在 reqwest::async 中。例如。 reqwest::async::Client::new(...).