【发布时间】:2015-05-28 11:06:04
【问题描述】:
为什么会这样
fn main() {
let test = "5% of foo".to_string();
let result: i32 = test.split('%').collect()[0].parse().unwrap_or(0);
}
导致错误
error[E0282]: type annotations needed
--> src/main.rs:4:23
|
4 | let result: i32 = test.split('%').collect()[0].parse().unwrap_or(0);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for `B`
这也无济于事:
let result: i32 = test.to_string().split('%').collect()[0].parse().unwrap_or(0i32);
【问题讨论】:
标签: rust