From 7625635050546f9498080c4c27b5b74711759eaa Mon Sep 17 00:00:00 2001 From: Jake Stanger Date: Mon, 15 Aug 2022 21:11:17 +0100 Subject: [PATCH] refactor: fix a couple of clippy warnings --- src/config.rs | 12 +++++++++--- src/main.rs | 29 ++++++++++++++++------------- src/modules/focused.rs | 5 +---- src/modules/workspaces.rs | 6 +++--- 4 files changed, 29 insertions(+), 23 deletions(-) diff --git a/src/config.rs b/src/config.rs index 102c252..e496539 100644 --- a/src/config.rs +++ b/src/config.rs @@ -41,7 +41,7 @@ pub enum BarPosition { impl Default for BarPosition { fn default() -> Self { - BarPosition::Bottom + Self::Bottom } } @@ -71,7 +71,13 @@ impl Config { pub fn load() -> Option { if let Ok(config_path) = env::var("IRONBAR_CONFIG") { let path = PathBuf::from(config_path); - Config::load_file(&path, path.extension().unwrap_or_default().to_str().unwrap_or_default()) + Self::load_file( + &path, + path.extension() + .unwrap_or_default() + .to_str() + .unwrap_or_default(), + ) } else { let config_dir = config_dir().expect("Failed to locate user config dir"); @@ -82,7 +88,7 @@ impl Config { .join("ironbar") .join(format!("config.{extension}")); - Config::load_file(&full_path, extension) + Self::load_file(&full_path, extension) }) } } diff --git a/src/main.rs b/src/main.rs index cc25f72..c876802 100644 --- a/src/main.rs +++ b/src/main.rs @@ -48,22 +48,25 @@ async fn main() { .expect("GTK monitor output differs from Sway's") .name; - if let Some(ref config) = config.monitors { - let config = config.get(monitor_name); - match &config { - Some(MonitorConfig::Single(config)) => { - create_bar(app, &monitor, monitor_name, config.clone()); - } - Some(MonitorConfig::Multiple(configs)) => { - for config in configs { + config.monitors.as_ref().map_or_else( + || { + create_bar(app, &monitor, monitor_name, config.clone()); + }, + |config| { + let config = config.get(monitor_name); + match &config { + Some(MonitorConfig::Single(config)) => { create_bar(app, &monitor, monitor_name, config.clone()); } + Some(MonitorConfig::Multiple(configs)) => { + for config in configs { + create_bar(app, &monitor, monitor_name, config.clone()); + } + } + _ => {} } - _ => {} - } - } else { - create_bar(app, &monitor, monitor_name, config.clone()); - } + }, + ) } let style_path = config_dir() diff --git a/src/modules/focused.rs b/src/modules/focused.rs index d629066..ac1c072 100644 --- a/src/modules/focused.rs +++ b/src/modules/focused.rs @@ -73,10 +73,7 @@ impl Module for FocusedModule { { rx.attach(None, move |node| { - let value = node - .name - .as_deref() - .unwrap_or_else(|| node.get_id()); + let value = node.name.as_deref().unwrap_or_else(|| node.get_id()); let pixbuf = icon::get_icon(&icon_theme, node.get_id(), self.icon_size); diff --git a/src/modules/workspaces.rs b/src/modules/workspaces.rs index 4dbf939..1ea1d94 100644 --- a/src/modules/workspaces.rs +++ b/src/modules/workspaces.rs @@ -51,13 +51,13 @@ impl Module for WorkspacesModule { let raw = sway.ipc(IpcCommand::GetWorkspaces).unwrap(); let workspaces = serde_json::from_slice::>(&raw).unwrap(); - if !self.all_monitors { + if self.all_monitors { + workspaces + } else { workspaces .into_iter() .filter(|workspace| workspace.output == info.output_name) .collect() - } else { - workspaces } };