1#[macro_use]
2extern crate serde_json;
3
4use std::env;
5use std::fs::File;
6use std::io::{Error, ErrorKind, Read, Write};
7
8pub mod data_struct;
9pub mod error;
10pub mod io_csv;
11pub mod io_json;
12pub mod io_yaml;
13pub use self::data_struct::*;
14
15pub fn read_file(path: &str) -> Result<String, Error> {
16 let mut f = File::open(path)?;
17
18 let mut contents = String::new();
19 f.read_to_string(&mut contents)?;
20 Ok(contents)
21}
22
23pub fn write_file(path: &str, text: &str) -> Result<(), Error> {
24 let mut file = File::create(path)?;
25 file.write_all(text.as_bytes())?;
26 Ok(())
27}
28
29fn create_io_error(msg: &str) -> Error {
31 Error::new(ErrorKind::Other, msg)
32}
33
34pub fn has_env(name: &str) -> bool {
35 match env::var(name) {
36 Ok(val) => {
37 if val.len() > 0 {
38 return true;
39 } else {
40 return false;
41 }
42 }
43 Err(_) => return false,
44 }
45}
46
47pub fn is_debug() -> bool {
48 has_env("DEBUG")
49}