问题描述
我只想从以下URL获取json。
所以我用了这段代码:
extern crate reqwest;
fn main() -> Result<(),Box<dyn std::error::Error>> {
let res = reqwest::Client::new()
.get("https://api.github.com/users/octocat")
.send()?
.text()?;
println!("{}",res);
Ok(())
}
但是我不知道如何解决该错误:
error[E0277]: the `?` operator can only be applied to values that implement `std::ops::Try`
--> src\main.rs:19:15
|
19 | let res = reqwest::Client::new()
| _______________^
20 | | .get("https://api.github.com/users/octocat")
21 | | .send()?
| |________________^ the `?` operator cannot be applied to type `impl std::future::Future`
|
= help: the trait `std::ops::Try` is not implemented for `impl std::future::Future`
= note: required by `std::ops::Try::into_result`
error: aborting due to previous error
For more information about this error,try `rustc --explain E0277`.
error: could not compile `Desktop`.
但是我也可以通过简单的方式获得想要的东西
curl https://api.github.com/users/octocat
我尝试添加use std::ops::Try;
,但效果不佳...
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)