1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use std::fs::File;
use std::io::{Error, ErrorKind, Read, Write};

pub mod data_struct;
pub mod error;
pub mod io_csv;
pub mod io_json;
pub mod io_yaml;

pub use self::data_struct::{Row, Tabular};

pub fn read_file(path: &str) -> Result<String, Error> {
    let mut f = File::open(path)?;

    let mut contents = String::new();
    f.read_to_string(&mut contents)?;
    Ok(contents)
}

pub fn write_file(path: &str, text: &str) -> Result<(), Error> {
    let mut file = File::create(path)?;
    file.write_all(text.as_bytes())?;
    Ok(())
}

fn create_io_error(msg: &str) -> Error {
    // errors can be created from strings
    Error::new(ErrorKind::Other, msg)
}