显然,某些事情发生了变化,因此我无法从字符串中解析i64:
use std::from_str::FromStr;
let tree1: BTreeMap<String, String> = //....
let my_i64: i64 = from_str(tree1.get("key1").unwrap().as_slice()).unwrap();
错误:
16:27 error: unresolved import `std::from_str::FromStr`. Could not find `from_str` in `std`
$ rustc -V
rustc 1.0.0-nightly (4be79d6ac 2015-01-23 16:08:14 +0000)
答案 0 :(得分:10)
导入失败,因为FromStr
特征现在是std::str::FromStr
。此外,from_str
已不在prelude
中。将字符串转换为整数的首选方法是str::parse
fn main() {
let i = "123".parse::<i64>();
println!("{:?}", i);
}
打印
Some(123)