2

Hyper を試すために、GET の例から始めました。例がコンパイルされない ( no method `get` in `client`) という事実は別として、問題を 1 行にまとめました。

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

このコードはコンパイルされません:

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

1 に答える 1

4

一般に、このエラーは、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 のものですかClient?

于 2016-09-07T12:30:46.823 に答える