2016-09-07 34 views
2

要试验Hyper,我从the GET example开始。除此之外的事实,例如没有编译(no method `get` in `client`)我已经蒸我的问题一行:无法创建hyper :: Client,因为编译器无法推断出足够的类型信息

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

此代码不能编译:

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

我为自己尝试了这一点,无法重现错误。你在文件中有'extern crate hyper;'和'hyper hyper :: Client'吗?这是我的工作版本:http://play.integer32.com/?gist=4debd4812508baf255f21715fbf44ef0 –

+0

将您的代码粘贴到我的main.rs.相同的错误 –

+0

好的。当我使用hyper-from-lang回购时,编译时,当我使用超级回购hyper时,{hyper = {git =“https://github.com/hyperium/hyper”} 这不会被编译。这也许可以解释为什么... –

回答

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没有任何泛型参数。你确定你想要实例化的Client是来自Hyper吗?

+0

是的,我使用hyper :: Client。我有一个使用Client的代码版本,一切正常,编译并运行。但是当我想重构这个错误时就出现了。 –

+0

因此,有一个通用参数: https://github.com/hyperium/hyper/blob/master/src/client/mod.rs 但我可能像你一样,看另一个文档: http ://hyper.rs/hyper/v0.9.4/hyper/client/index.html 其中没有通用参数 –

相关问题