Advertisement
Guest User

Untitled

a guest
Nov 9th, 2014
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.87 KB | None | 0 0
  1. extern crate serialize;
  2.  
  3. use std::io::File;
  4. use serialize::json;
  5. use std::collections::TreeMap;
  6.  
  7. fn main () {
  8.  
  9.     let fname = "/home/alex/src/bench/jsonParse/data/39m.json";
  10.  
  11.     let path = Path::new (fname);
  12.  
  13.     // Open the file path
  14.     let display = path.display();
  15.     let mut file = match File::open (&path) {
  16.         Err(why) => fail!("{} {}",display ,why.desc),
  17.         Ok(file) => file,
  18.     };
  19.  
  20.     // Read the file contents into a heap allocated string
  21.     let contents = match file.read_to_str() {
  22.         Err(why) => fail!("{}", why.desc),
  23.         Ok(text) => text,
  24.     };
  25.  
  26.     // Parse the file contents into Rust valid JSON object
  27.     let json = match json::from_str (contents.as_slice()) {
  28.         Ok(json) => json,
  29.         Err(err) => fail!("Invalid JSON. {}", err)
  30.     };
  31.    
  32.     // println! ("{}", std::collections::TreeMap::map.len (json));
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement