为了试验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]

最佳答案

通常,此错误将意味着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中的ojit_code吗?

10-02 02:29
查看更多