Skip to content

Commit

Permalink
🎨 reduce nesting in config read function
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm committed Oct 21, 2024
1 parent f9ac22c commit 975c1f0
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions src/modules/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,26 @@ const CONFIG_FILE_NAME: &str = "wthrr.ron";
impl Config {
pub fn get() -> Self {
let mut config = Self::default();

let path = Self::get_path();
let file = fs::read_to_string(&path);
let file = if let Ok(f) = file { f } else { return config };

Check warning on line 57 in src/modules/config.rs

View workflow job for this annotation

GitHub Actions / Lint / clippy

this could be rewritten as `let...else`

warning: this could be rewritten as `let...else` --> src/modules/config.rs:57:3 | 57 | let file = if let Ok(f) = file { f } else { return config }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `let Ok(file) = file else { return config };` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_let_else note: the lint level is defined here --> src/main.rs:2:9 | 2 | #![warn(clippy::pedantic)] | ^^^^^^^^^^^^^^^^ = note: `#[warn(clippy::manual_let_else)]` implied by `#[warn(clippy::pedantic)]`

if let Ok(file) = fs::read_to_string(&path) {
match Options::default()
.with_default_extension(Extensions::IMPLICIT_SOME)
.from_str::<ConfigFile>(&file)
{
Ok(contents) => contents.apply_to(&mut config),
Err(error) => {
let warning_sign = style(" Warning:").yellow();
eprintln!(
"{warning_sign} {}\n{: >4}At: {error}.\n{: >4}Falling back to default values.\n",
path.display(),
"",
"",
);
return config;
}
};
}
match Options::default()
.with_default_extension(Extensions::IMPLICIT_SOME)
.from_str::<ConfigFile>(&file)
{
Ok(contents) => contents.apply_to(&mut config),
Err(error) => {
let warning = style(" Warning:").yellow();
eprintln!(
"{warning} {0}\n{1: >4}At: {error}.\n{1: >4}Falling back to default values.\n",
path.display(),
"",
);
return config;
}
};

config
}
Expand Down

0 comments on commit 975c1f0

Please sign in to comment.