问题描述
我正在尝试运行基本的reqwest
示例:
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(())
}
我遇到的错误:
--> 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"] }
有人知道这是怎么回事吗?
Does anybody know what is wrong here?
推荐答案
与此处相同,只是相反.您正在使用reqwest-0.9
,默认情况下使用的是阻止接口.更新到reqwest-0.10
以获得异步接口.
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.
如果无法更新到reqwest-0.10
,则reqwest-0.9
中的异步接口位于reqwest::async
中.例如. reqwest::async::Client::new(...)
.
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(...)
.
这篇关于没有为`std :: result :: Result< reqwest :: Response,reqwest :: Error>`实现特性`std :: future :: Future`.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!