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

烈酒焚心 提交于 2020-05-29 09:41:58

问题


I'm trying to run basic 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(())
}

Error that I'm getting:

   --> 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 version: rustc 1.39.0 (4560ea788 2019-11-04)

Library versions:

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

Does anybody know what is wrong here?


回答1:


Same problem as here, just in reverse. You are using reqwest-0.9, which is using the blocking interface by default. Update to reqwest-0.10 to get the async interface.

If you can't update to reqwest-0.10, the async interface in reqwest-0.9 is in reqwest::async. E.g. reqwest::async::Client::new(...).



来源:https://stackoverflow.com/questions/59125573/the-trait-stdfuturefuture-is-not-implemented-for-stdresultresultreqw

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!