2

To experiment with Hyper, I started with the GET example. Aside the fact that the example doesn't compile (no method `get` in `client`) I have distilled my problem to a single line:

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

This code won't compile:

 unable to infer enough type information about `_`; type annotations or generic parameter binding required [E0282]
Lukas Kalbertodt
  • 79,749
  • 26
  • 255
  • 305
Roman Smelyansky
  • 319
  • 1
  • 13
  • 2
    I tried this out for myself and couldn't reproduce the error. Do you have `extern crate hyper;` and `use hyper::Client;` in your file? Here's my working version: http://play.integer32.com/?gist=4debd4812508baf255f21715fbf44ef0 – Joe Clay Sep 07 '16 at 12:29
  • Pasted your code into my main.rs. Same error – Roman Smelyansky Sep 07 '16 at 13:25
  • Ok. When I use hyper from rust-lang repo this compiles, when I use hyper from hyper repo hyper={git = "https://github.com/hyperium/hyper"} This won't compile. That maybe explains why... – Roman Smelyansky Sep 07 '16 at 13:29

1 Answers1

4

In general this error would mean that Client has some generic parameter and the compiler can not infer it's value. You would have to tell it somehow.

Here is example with 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
}

But hyper::client::Client doesn't have any generic parameters. Are you sure the Client you are trying to instantiate is the one from Hyper?

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
michalsrb
  • 4,703
  • 1
  • 18
  • 35
  • Yes, I use the hyper::Client. I have a version of my code that uses Client and all is well, compiles and runs. But when I wanted to refactor this error came up. – Roman Smelyansky Sep 07 '16 at 13:26
  • So, there is a generic parameter: https://github.com/hyperium/hyper/blob/master/src/client/mod.rs But I, probably as you did, looked in another documentation: http://hyper.rs/hyper/v0.9.4/hyper/client/index.html where there is no generic parameter – Roman Smelyansky Sep 07 '16 at 13:33