Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
601 views
in Technique[技术] by (71.8m points)

rust - 没有为`std :: result :: Result实现特质`std :: future :: Future` <reqwest::Response, reqwest::Error> `(The trait `std::future::Future` is not implemented for `std::result::Result<reqwest::Response, reqwest::Error>`)

I'm trying to run basic reqwest example :

(我正在尝试运行基本的reqwest 示例 :)

  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:

{}", 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)

(Rust版本: 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?

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

  ask by semanser translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Same problem as here , just in reverse.

(与这里相同的问题,只是相反。)

You are using reqwest-0.9 , which is using the blocking interface by default.

(您正在使用reqwest-0.9 ,默认情况下使用的是阻塞接口。)

Update to reqwest-0.10 to get the async interface.

(更新到reqwest-0.10以获得异步接口。)

If you can't update to reqwest-0.10 , the async interface in reqwest-0.9 is in reqwest::async .

(如果您无法更新到reqwest-0.10 ,则reqwest-0.9的async接口位于reqwest::async 。)

Eg reqwest::async::Client::new(...) .

(例如reqwest::async::Client::new(...))


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...