`std::result::Result` 没有实现 `std::future::Future` 特性

2023-12-13

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

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


同样的问题here,正好相反。您正在使用reqwest-0.9,默认使用阻塞接口。更新至reqwest-0.10获取异步接口。

如果您无法更新到reqwest-0.10,异步接口reqwest-0.9 is in reqwest::async. E.g. reqwest::async::Client::new(...).

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

`std::result::Result` 没有实现 `std::future::Future` 特性 的相关文章

随机推荐