Fix clippy lints

This commit is contained in:
elkowar 2021-05-03 23:24:11 +02:00
parent c130dbe37b
commit a1a313be70
No known key found for this signature in database
GPG key ID: E321AD71B1D1F27F
12 changed files with 26 additions and 31 deletions

View file

@ -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::<Result<()>>();
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 } => {

View file

@ -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()?)?,
}

View file

@ -24,7 +24,7 @@ pub struct EwwConfig {
}
impl EwwConfig {
pub fn read_from_file<P: AsRef<std::path::Path>>(path: P) -> Result<Self> {
Ok(Self::generate(RawEwwConfig::read_from_file(path)?)?)
Self::generate(RawEwwConfig::read_from_file(path)?)
}
pub fn generate(conf: RawEwwConfig) -> Result<Self> {
@ -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::<Result<Vec<_>>>()
.with_context(|| format!("Included in {}", path.as_ref().display()))?;

View file

@ -51,7 +51,7 @@ impl ScriptVar {
pub fn from_xml_element(xml: XmlElement) -> Result<Self> {
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)?;

View file

@ -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 <reserve>")?;
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(),

View file

@ -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"))

View file

@ -101,12 +101,12 @@ pub fn parse_duration(s: &str) -> Result<std::time::Duration> {
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::<u64>()? * 60))
} else if s.ends_with("h") {
Ok(Duration::from_secs(s.trim_end_matches("h").parse::<u64>()? * 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::<u64>()? * 60))
} else if s.ends_with('h') {
Ok(Duration::from_secs(s.trim_end_matches('h').parse::<u64>()? * 60 * 60))
} else {
Err(anyhow!("unrecognized time format: {}", s))
}

View file

@ -193,7 +193,7 @@ impl AttrValExpr {
}
}
pub fn parse<'a>(s: &'a str) -> Result<Self> {
pub fn parse(s: &str) -> Result<Self> {
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))),

View file

@ -23,7 +23,7 @@ where
fn parse_num(i: &str) -> IResult<&str, i32, VerboseError<&str>> {
alt((
map_res(digit1, |s: &str| s.parse::<i32>()),
map_res(preceded(tag("-"), digit1), |s: &str| s.parse::<i32>().map(|x| x * -1)),
map_res(preceded(tag("-"), digit1), |s: &str| s.parse::<i32>().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)
}

View file

@ -131,7 +131,7 @@ fn parse_vec(a: String) -> Result<Vec<String>> {
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] += ",";

View file

@ -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<gtk::ComboBoxText
prop(onchange: as_string) {
let old_id = on_change_handler_id.replace(Some(
gtk_widget.connect_changed(move |gtk_widget| {
run_command(&onchange, gtk_widget.get_active_text().unwrap_or("".into()));
run_command(&onchange, gtk_widget.get_active_text().unwrap_or_else(|| "".into()));
})
));
old_id.map(|id| gtk_widget.disconnect(id));
@ -285,7 +286,7 @@ fn build_gtk_color_chooser(bargs: &mut BuilderArgs) -> Result<gtk::ColorChooserW
prop(onchange: as_string) {
let old_id = on_change_handler_id.replace(Some(
gtk_widget.connect_color_activated(move |_a, color| {
run_command(&onchange, color.clone());
run_command(&onchange, *color);
})
));
old_id.map(|id| gtk_widget.disconnect(id));

View file

@ -91,8 +91,8 @@ impl WidgetNode for Generic {
window_name: &WindowName,
widget_definitions: &HashMap<String, WidgetDefinition>,
) -> Result<gtk::Widget> {
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()))
}
}