14

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
  • 388,571
  • 95
  • 1,107
  • 1,366
Incerteza
  • 32,326
  • 47
  • 154
  • 261

1 Answers1

37

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
  • 1,007
  • 9
  • 17
Dogbert
  • 212,659
  • 41
  • 396
  • 397