mirror of
https://gitlab.com/gabmus/envision.git
synced 2025-04-20 03:24:52 +00:00
fix: use unwrap_or_deafult to simplify config loading logic
This commit is contained in:
parent
b63b63efaf
commit
5ff160241d
1 changed files with 4 additions and 10 deletions
|
@ -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> {
|
||||
|
|
Loading…
Add table
Reference in a new issue