fix: use unwrap_or_deafult to simplify config loading logic

This commit is contained in:
Gabriele Musco 2024-09-05 22:58:58 +02:00
parent b63b63efaf
commit 5ff160241d

View file

@ -65,16 +65,10 @@ impl Config {
}
fn from_path(path: &Path) -> Self {
match File::open(path) {
Ok(file) => {
let reader = BufReader::new(file);
match serde_json::from_reader(reader) {
Ok(config) => config,
Err(_) => Self::default(),
}
}
Err(_) => Self::default(),
}
File::open(path)
.ok()
.and_then(|file| serde_json::from_reader(BufReader::new(file)).ok())
.unwrap_or_default()
}
fn save_to_path(&self, path: &Path) -> Result<(), serde_json::Error> {