mirror of
https://gitlab.com/gabmus/envision.git
synced 2025-08-01 05:38:44 +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 {
|
fn from_path(path: &Path) -> Self {
|
||||||
match File::open(path) {
|
File::open(path)
|
||||||
Ok(file) => {
|
.ok()
|
||||||
let reader = BufReader::new(file);
|
.and_then(|file| serde_json::from_reader(BufReader::new(file)).ok())
|
||||||
match serde_json::from_reader(reader) {
|
.unwrap_or_default()
|
||||||
Ok(config) => config,
|
|
||||||
Err(_) => Self::default(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(_) => Self::default(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn save_to_path(&self, path: &Path) -> Result<(), serde_json::Error> {
|
fn save_to_path(&self, path: &Path) -> Result<(), serde_json::Error> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue