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

时间:2019-12-01 12:39:28

标签: rust async-await rust-tokio reqwest

我正在尝试运行基本的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>`

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

库版本:

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

有人知道这是怎么回事吗?

1 个答案:

答案 0 :(得分:3)

here相同的问题,只是相反。您正在使用reqwest-0.9,默认情况下使用的是阻止接口。更新到reqwest-0.10以获得异步接口。

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