diff --git a/src/app.rs b/src/app.rs index fdf8918..42a5ab7 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,6 +1,6 @@ use crate::{ config, - config::{window_definition::WindowName, AnchorPoint, WindowStacking}, + config::{window_definition::WindowName, AnchorPoint}, display_backend, eww_state, script_var_handler::*, value::{Coords, NumWithUnit, PrimVal, VarName}, @@ -24,10 +24,7 @@ pub enum DaemonResponse { impl DaemonResponse { pub fn is_success(&self) -> bool { - match self { - DaemonResponse::Success(_) => true, - _ => false, - } + matches!(self, DaemonResponse::Success(_)) } pub fn is_failure(&self) -> bool { @@ -149,7 +146,7 @@ impl App { } } DaemonCommand::OpenMany { windows, sender } => { - let result = windows.iter().map(|w| self.open_window(w, None, None, None, None)).collect::>(); + let result = windows.iter().try_for_each(|w| self.open_window(w, None, None, None, None)); respond_with_error(sender, result)?; } DaemonCommand::OpenWindow { window_name, pos, size, anchor, monitor, sender } => { diff --git a/src/config/element.rs b/src/config/element.rs index 6f37f8e..373aafa 100644 --- a/src/config/element.rs +++ b/src/config/element.rs @@ -29,7 +29,7 @@ impl WidgetDefinition { } WidgetDefinition { - name: xml.attr("name")?.to_owned(), + name: xml.attr("name")?, size: Option::zip(xml.parse_optional_attr("width")?, xml.parse_optional_attr("height")?), structure: WidgetUse::from_xml_node(xml.only_child()?)?, } diff --git a/src/config/eww_config.rs b/src/config/eww_config.rs index 0bc1491..8a8bb1f 100644 --- a/src/config/eww_config.rs +++ b/src/config/eww_config.rs @@ -24,7 +24,7 @@ pub struct EwwConfig { } impl EwwConfig { pub fn read_from_file>(path: P) -> Result { - Ok(Self::generate(RawEwwConfig::read_from_file(path)?)?) + Self::generate(RawEwwConfig::read_from_file(path)?) } pub fn generate(conf: RawEwwConfig) -> Result { @@ -121,7 +121,7 @@ impl RawEwwConfig { let parsed_includes = included_paths .into_iter() - .map(|included_path| Self::read_from_file(included_path)) + .map(Self::read_from_file) .collect::>>() .with_context(|| format!("Included in {}", path.as_ref().display()))?; diff --git a/src/config/script_var.rs b/src/config/script_var.rs index 6ef6ede..9eba0b7 100644 --- a/src/config/script_var.rs +++ b/src/config/script_var.rs @@ -51,7 +51,7 @@ impl ScriptVar { pub fn from_xml_element(xml: XmlElement) -> Result { ensure_xml_tag_is!(xml, "script-var"); - let name = VarName(xml.attr("name")?.to_owned()); + let name = VarName(xml.attr("name")?); let command = xml.only_child()?.as_text()?.text(); if let Ok(interval) = xml.attr("interval") { let interval = util::parse_duration(&interval)?; diff --git a/src/config/window_definition.rs b/src/config/window_definition.rs index 042d928..00ac348 100644 --- a/src/config/window_definition.rs +++ b/src/config/window_definition.rs @@ -1,8 +1,4 @@ -use crate::{ - ensure_xml_tag_is, - value::{Coords, NumWithUnit}, - widgets::widget_node, -}; +use crate::{ensure_xml_tag_is, value::NumWithUnit, widgets::widget_node}; use anyhow::*; use derive_more::*; use serde::{Deserialize, Serialize}; @@ -93,7 +89,7 @@ impl RawEwwWindowDefinition { xml.child("reserve").ok().map(StrutDefinition::from_xml_element).transpose().context("Failed to parse ")?; Ok(RawEwwWindowDefinition { - name: WindowName(xml.attr("name")?.to_owned()), + name: WindowName(xml.attr("name")?), geometry: match xml.child("geometry") { Ok(node) => EwwWindowGeometry::from_xml_element(node)?, Err(_) => EwwWindowGeometry::default(), diff --git a/src/main.rs b/src/main.rs index 637f65a..87b6712 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,6 +6,7 @@ #![feature(try_blocks)] #![feature(nll)] + extern crate gio; extern crate gtk; #[cfg(feature = "wayland")] @@ -126,7 +127,7 @@ impl EwwPaths { let daemon_id = base64::encode(format!("{}", config_dir.display())); Ok(EwwPaths { - config_dir: config_dir.to_path_buf(), + config_dir, log_file: std::env::var("XDG_CACHE_HOME") .map(PathBuf::from) .unwrap_or_else(|_| PathBuf::from(std::env::var("HOME").unwrap()).join(".cache")) diff --git a/src/util.rs b/src/util.rs index 8026c98..2a78896 100644 --- a/src/util.rs +++ b/src/util.rs @@ -101,12 +101,12 @@ pub fn parse_duration(s: &str) -> Result { use std::time::Duration; if s.ends_with("ms") { Ok(Duration::from_millis(s.trim_end_matches("ms").parse()?)) - } else if s.ends_with("s") { - Ok(Duration::from_secs(s.trim_end_matches("s").parse()?)) - } else if s.ends_with("m") { - Ok(Duration::from_secs(s.trim_end_matches("m").parse::()? * 60)) - } else if s.ends_with("h") { - Ok(Duration::from_secs(s.trim_end_matches("h").parse::()? * 60 * 60)) + } else if s.ends_with('s') { + Ok(Duration::from_secs(s.trim_end_matches('s').parse()?)) + } else if s.ends_with('m') { + Ok(Duration::from_secs(s.trim_end_matches('m').parse::()? * 60)) + } else if s.ends_with('h') { + Ok(Duration::from_secs(s.trim_end_matches('h').parse::()? * 60 * 60)) } else { Err(anyhow!("unrecognized time format: {}", s)) } diff --git a/src/value/attr_value/attr_value_expr.rs b/src/value/attr_value/attr_value_expr.rs index 0a4bca0..a2663db 100644 --- a/src/value/attr_value/attr_value_expr.rs +++ b/src/value/attr_value/attr_value_expr.rs @@ -193,7 +193,7 @@ impl AttrValExpr { } } - pub fn parse<'a>(s: &'a str) -> Result { + pub fn parse(s: &str) -> Result { let parsed = match parser::parse(s) { Ok((_, x)) => Ok(x), Err(nom::Err::Error(e) | nom::Err::Failure(e)) => Err(anyhow!(nom::error::convert_error(s, e))), diff --git a/src/value/attr_value/parser.rs b/src/value/attr_value/parser.rs index e345d80..bf70b86 100644 --- a/src/value/attr_value/parser.rs +++ b/src/value/attr_value/parser.rs @@ -23,7 +23,7 @@ where fn parse_num(i: &str) -> IResult<&str, i32, VerboseError<&str>> { alt(( map_res(digit1, |s: &str| s.parse::()), - map_res(preceded(tag("-"), digit1), |s: &str| s.parse::().map(|x| x * -1)), + map_res(preceded(tag("-"), digit1), |s: &str| s.parse::().map(|x| -x)), ))(i) } @@ -140,7 +140,7 @@ fn parse_ifelse(i: &str) -> IResult<&str, AttrValExpr, VerboseError<&str>> { Ok((i, AttrValExpr::IfElse(box a, box b, box c))) } -pub fn parse<'a>(i: &'a str) -> IResult<&'a str, AttrValExpr, VerboseError<&'a str>> { +pub fn parse(i: &str) -> IResult<&str, AttrValExpr, VerboseError<&str>> { complete(parse_expr)(i) } diff --git a/src/value/primitive.rs b/src/value/primitive.rs index 2ef4cb2..1dbbf4f 100644 --- a/src/value/primitive.rs +++ b/src/value/primitive.rs @@ -131,7 +131,7 @@ fn parse_vec(a: String) -> Result> { let mut removed = 0; for times_ran in 0..items.len() { // escapes `,` if there's a `\` before em - if items[times_ran - removed].ends_with("\\") { + if items[times_ran - removed].ends_with('\\') { items[times_ran - removed].pop(); let it = items.remove((times_ran + 1) - removed); items[times_ran - removed] += ","; diff --git a/src/widgets/widget_definitions.rs b/src/widgets/widget_definitions.rs index f5143a7..2edf728 100644 --- a/src/widgets/widget_definitions.rs +++ b/src/widgets/widget_definitions.rs @@ -1,3 +1,4 @@ +#![allow(clippy::option_map_unit_fn)] use super::{run_command, BuilderArgs}; use crate::{config, eww_state, resolve_block, value::AttrVal, widgets::widget_node}; use anyhow::*; @@ -203,7 +204,7 @@ fn build_gtk_combo_box_text(bargs: &mut BuilderArgs) -> Result Result, ) -> Result { - Ok(crate::widgets::build_builtin_gtk_widget(eww_state, window_name, widget_definitions, &self)? - .with_context(|| format!("Unknown widget '{}'", self.get_name()))?) + crate::widgets::build_builtin_gtk_widget(eww_state, window_name, widget_definitions, &self)? + .with_context(|| format!("Unknown widget '{}'", self.get_name())) } }