我只是想将输入的字符串转换为整数。我知道这可以通过将unwrap
应用到from_str
来完成,但我想我会尝试正确处理错误情况并改为使用匹配提取值。相反,它按预期工作我刚刚得到这个错误...从匹配的选项提取值给出“无法推断出足够的类型信息...”错误
error: unable to infer enough type information about
_
; type annotations requiredwhich points to the
xin
Some(x)`
fn main() {
let ref num = os::args()[1];
match from_str(num.as_slice()) {
Some(x) => println!("{}", x),
None => println!("string cannot be converted to int"),
}
}
我缺少什么?
谢谢您的详细解释! – AllTheTime 2014-12-05 06:50:00