问题
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