为了试验 Hyper,我从 the GET example 开始。除了该示例无法编译这一事实之外(`client` 中没有方法 `get`
),我已将问题简化为一行:
fn temp() {
let client = Client::new();
}
此代码无法编译:
unable to infer enough type information about `_`; type annotations or generic parameter binding required [E0282]
最佳答案
一般来说,此错误意味着 Client
有一些通用参数,并且编译器无法推断它的值。你必须以某种方式告诉它。
这是 std::vec::Vec
的示例:
use std::vec::Vec;
fn problem() {
let v = Vec::new(); // Problem, which Vec<???> do you want?
}
fn solution_1() {
let mut v = Vec::<i32>::new(); // Tell the compiler directly
}
fn solution_2() {
let mut v: Vec<i32> = Vec::new(); // Tell the compiler by specifying the type
}
fn solution_3() {
let mut v = Vec::new();
v.push(1); // Tell the compiler by using it
}
但是 hyper::client::Client
没有任何通用参数。您确定您尝试实例化的 Client
是来自 Hyper 的吗?
关于rust - 无法创建 hyper::Client,因为编译器无法推断出足够的类型信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39369650/