Implement basic config loading and updating. No save to file yet.

This commit is contained in:
Daniel García
2019-02-02 16:47:27 +01:00
parent 86ed75bf7c
commit 877408b808
6 changed files with 173 additions and 90 deletions

View File

@@ -77,6 +77,15 @@ pub fn read_file(path: &str) -> IOResult<Vec<u8>> {
Ok(contents)
}
pub fn read_file_string(path: &str) -> IOResult<String> {
let mut contents = String::new();
let mut file = File::open(Path::new(path))?;
file.read_to_string(&mut contents)?;
Ok(contents)
}
pub fn delete_file(path: &str) -> IOResult<()> {
let res = fs::remove_file(path);
@@ -284,25 +293,3 @@ where
}
}
}
//
// Into Result
//
use crate::error::Error;
pub trait IntoResult<T> {
fn into_result(self) -> Result<T, Error>;
}
impl<T> IntoResult<T> for Result<T, Error> {
fn into_result(self) -> Result<T, Error> {
self
}
}
impl<T> IntoResult<T> for T {
fn into_result(self) -> Result<T, Error> {
Ok(self)
}
}