From bc625b929b8644ce92f275b5d98cdf74b93fe067 Mon Sep 17 00:00:00 2001 From: Jake Stanger Date: Sat, 5 Nov 2022 17:32:42 +0000 Subject: [PATCH] refactor: clippy & fmt --- src/main.rs | 10 +++++----- src/modules/custom.rs | 16 ++++++++-------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main.rs b/src/main.rs index edfd55b..322070f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -95,10 +95,8 @@ async fn main() -> Result<()> { debug!("Created bars"); - let style_path = env::var("IRONBAR_CSS") - .ok() - .map(PathBuf::from) - .unwrap_or_else(|| { + let style_path = env::var("IRONBAR_CSS").ok().map_or_else( + || { config_dir().map_or_else( || { let report = Report::msg("Failed to locate user config dir"); @@ -107,7 +105,9 @@ async fn main() -> Result<()> { }, |dir| dir.join("ironbar").join("style.css"), ) - }); + }, + PathBuf::from, + ); if style_path.exists() { load_css(style_path); diff --git a/src/modules/custom.rs b/src/modules/custom.rs index a0c20b3..c1b5736 100644 --- a/src/modules/custom.rs +++ b/src/modules/custom.rs @@ -20,7 +20,7 @@ pub struct CustomModule { } /// Attempts to parse an `Orientation` from `String` -fn try_get_orientation(orientation: String) -> Result { +fn try_get_orientation(orientation: &str) -> Result { match orientation.to_lowercase().as_str() { "horizontal" | "h" => Ok(Orientation::Horizontal), "vertical" | "v" => Ok(Orientation::Vertical), @@ -55,14 +55,14 @@ impl Widget { /// Creates this widget and adds it to the parent container fn add_to(self, parent: >k::Box, tx: Sender, bar_orientation: Orientation) { match self.widget_type { - WidgetType::Box => parent.add(&self.into_box(tx, bar_orientation)), + WidgetType::Box => parent.add(&self.into_box(&tx, bar_orientation)), WidgetType::Label => parent.add(&self.into_label()), WidgetType::Button => parent.add(&self.into_button(tx, bar_orientation)), } } /// Creates a `gtk::Box` from this widget - fn into_box(self, tx: Sender, bar_orientation: Orientation) -> gtk::Box { + fn into_box(self, tx: &Sender, bar_orientation: Orientation) -> gtk::Box { let mut builder = gtk::Box::builder(); if let Some(name) = self.name { @@ -71,7 +71,7 @@ impl Widget { if let Some(orientation) = self.orientation { builder = builder - .orientation(try_get_orientation(orientation).unwrap_or(Orientation::Horizontal)); + .orientation(try_get_orientation(&orientation).unwrap_or(Orientation::Horizontal)); } let container = builder.build(); @@ -83,7 +83,7 @@ impl Widget { if let Some(widgets) = self.widgets { widgets .into_iter() - .for_each(|widget| widget.add_to(&container, tx.clone(), bar_orientation)) + .for_each(|widget| widget.add_to(&container, tx.clone(), bar_orientation)); } container @@ -198,11 +198,11 @@ impl Module for CustomModule { let container = gtk::Box::builder().orientation(orientation).build(); if let Some(ref class) = self.class { - container.style_context().add_class(class) + container.style_context().add_class(class); } self.bar.clone().into_iter().for_each(|widget| { - widget.add_to(&container, context.controller_tx.clone(), orientation) + widget.add_to(&container, context.controller_tx.clone(), orientation); }); let popup = self.into_popup(context.controller_tx, context.popup_rx); @@ -226,7 +226,7 @@ impl Module for CustomModule { if let Some(class) = self.class { container .style_context() - .add_class(format!("popup-{class}").as_str()) + .add_class(format!("popup-{class}").as_str()); } if let Some(popup) = self.popup {