Modernize

This commit is contained in:
2022-06-08 15:36:08 -07:00
parent a3c2f84223
commit fa2542f361
7 changed files with 63 additions and 87 deletions

View File

@ -86,12 +86,11 @@ pub struct Config {
}
impl Config {
pub fn parse<P: AsRef<Path>>(filename: P) -> Result<Config, String> {
let mut f = File::open(filename).map_err(|err| err.to_string())?;
pub fn parse<P: AsRef<Path>>(filename: P) -> anyhow::Result<Config> {
let mut f = File::open(filename)?;
let mut contents = String::new();
f.read_to_string(&mut contents)
.map_err(|err| err.to_string())?;
let config: Config = from_str(&contents).map_err(|err| err.to_string())?;
f.read_to_string(&mut contents)?;
let config: Config = from_str(&contents)?;
Ok(config)
}
}