无法创建hyper :: Client,因为编译器无法推断出足够的类型信息

时间:2016-09-07 12:12:07

标签: rust type-inference hyper

为了试验Hyper,我从the GET example开始。除了示例不编译(no method `get` in `client`)之外,我已将我的问题提炼为一行:

fn temp() {
    let client = Client::new();
}

此代码无法编译:

 unable to infer enough type information about `_`; type annotations or generic parameter binding required [E0282]

1 个答案:

答案 0 :(得分:4)

通常,此错误意味着admin具有一些通用参数,编译器无法推断它的值。你不得不以某种方式告诉它。

以下是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是来自Hyper的那个吗?