12

Apparently, something has changed and thus I can't parse i64 from string:

use std::from_str::FromStr;

let tree1: BTreeMap<String, String> = //....
let my_i64: i64 = from_str(tree1.get("key1").unwrap().as_slice()).unwrap();

Error:

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)
Shepmaster
  • 326,504
  • 69
  • 892
  • 1,159
Incerteza
  • 27,981
  • 42
  • 142
  • 242

1 Answers1

28

Your import fails because the FromStr trait is now std::str::FromStr. Also, from_str is no longer in the prelude. The preferred way to convert strings to integers is str::parse

fn main() {
    let i = "123".parse::<i64>();
    println!("{:?}", i);
}

prints

Ok(123)

Demo

smbear
  • 997
  • 9
  • 16
Dogbert
  • 200,802
  • 40
  • 378
  • 386