TOML File example:
[[zone]]
abbr="GMT"
name="Greenwich Mean Time"
utcoffset="UTC0"
insec=0
[[zone]]
abbr="UTC"
name="Universal Time Coordinated"
utcoffset="UTC0"
insec=0
[[zone]]
abbr="ACDT"
name="Australian Central Daylight Savings Time"
utcoffset="UTC+10:30"
insec=37800
cargo.toml
...
[dependencies]
# libc = "*"
toml = "0.2"
rustc-serialize = "0.3.19"
...
Code:
extern crate toml;
extern crate rustc_serialize;
use std::env;
use std::fs;
use std::fs::{File, OpenOptions};
use std::io;
use std::io::prelude::*;
// use std::os::unix;
use std::path::Path;
use toml::Value;
use rustc_serialize::Decodable;
use rustc_serialize::Decoder;
#[derive(RustcDecodable,Debug)]
struct TZone {
abbr : Option<String>
, name : Option<String>
, utcoffset : Option<String>
, insec : Option<u32>
}
#[derive(RustcDecodable,Debug)]
struct TZVec {
zone : Option<Vec<TZone>>
}
fn main() {
// get Current Directory
let cwd :String = match env::current_exe() {
Ok(c) => c.display().to_string()
, Err(e) => panic!("Error processing envirnment variable of current_exe dir - Err: {}!", e)
};
println!(">> Current Working Directory: {}", cwd);
// Zones File
let zone_file = "C:\\Users\\CBHATTARAM\\Workspace\\biff\\data\\zones.toml";
let mut zhdl = match File::open(zone_file) {
Ok(f) => f
, Err(e) => panic!("Error occurred opening file: {} - Err: {}", zone_file, e)
};
let mut zstr = String::new();
match zhdl.read_to_string(&mut zstr) {
Ok(s) => s
, Err(e) => panic!("Error Reading file: {}", e)
};
println!("Zone File: {}", zone_file);
let tml :TZVec = toml::decode_str(&zstr).unwrap();
for x in tml.zone.unwrap() {
// println!("X: {:?}", x);
}
// Read Directory
}