1use errors::*;
5use std::fs::File;
6use std::io::{Write, Read};
7
8pub fn write_file(data: &str, path: &str) -> Result<()> {
10 File::create(&path)
12 .chain_err(|| format!("Failed to open file {} for writing", &path))?
13 .write_all(data.as_bytes())
14 .chain_err(|| format!("Failed to write to file {}", &path))?;
15 Ok(())
16}
17
18pub fn read_file(path: &str) -> Result<String> {
20 let mut value_str = String::new();
21
22 let _ = File::open(path)
24 .chain_err(|| format!("Failed to open file {} for reading", &path))?
25 .read_to_string(&mut value_str)
26 .chain_err(|| format!("Failed to read from file {}", &path))?;
27
28 Ok(value_str)
29}