Fix clippy lints
This commit is contained in:
parent
c130dbe37b
commit
a1a313be70
12 changed files with 26 additions and 31 deletions
|
@ -1,6 +1,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
config,
|
config,
|
||||||
config::{window_definition::WindowName, AnchorPoint, WindowStacking},
|
config::{window_definition::WindowName, AnchorPoint},
|
||||||
display_backend, eww_state,
|
display_backend, eww_state,
|
||||||
script_var_handler::*,
|
script_var_handler::*,
|
||||||
value::{Coords, NumWithUnit, PrimVal, VarName},
|
value::{Coords, NumWithUnit, PrimVal, VarName},
|
||||||
|
@ -24,10 +24,7 @@ pub enum DaemonResponse {
|
||||||
|
|
||||||
impl DaemonResponse {
|
impl DaemonResponse {
|
||||||
pub fn is_success(&self) -> bool {
|
pub fn is_success(&self) -> bool {
|
||||||
match self {
|
matches!(self, DaemonResponse::Success(_))
|
||||||
DaemonResponse::Success(_) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_failure(&self) -> bool {
|
pub fn is_failure(&self) -> bool {
|
||||||
|
@ -149,7 +146,7 @@ impl App {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DaemonCommand::OpenMany { windows, sender } => {
|
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)?;
|
respond_with_error(sender, result)?;
|
||||||
}
|
}
|
||||||
DaemonCommand::OpenWindow { window_name, pos, size, anchor, monitor, sender } => {
|
DaemonCommand::OpenWindow { window_name, pos, size, anchor, monitor, sender } => {
|
||||||
|
|
|
@ -29,7 +29,7 @@ impl WidgetDefinition {
|
||||||
}
|
}
|
||||||
|
|
||||||
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")?),
|
size: Option::zip(xml.parse_optional_attr("width")?, xml.parse_optional_attr("height")?),
|
||||||
structure: WidgetUse::from_xml_node(xml.only_child()?)?,
|
structure: WidgetUse::from_xml_node(xml.only_child()?)?,
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ pub struct EwwConfig {
|
||||||
}
|
}
|
||||||
impl EwwConfig {
|
impl EwwConfig {
|
||||||
pub fn read_from_file<P: AsRef<std::path::Path>>(path: P) -> Result<Self> {
|
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> {
|
pub fn generate(conf: RawEwwConfig) -> Result<Self> {
|
||||||
|
@ -121,7 +121,7 @@ impl RawEwwConfig {
|
||||||
|
|
||||||
let parsed_includes = included_paths
|
let parsed_includes = included_paths
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|included_path| Self::read_from_file(included_path))
|
.map(Self::read_from_file)
|
||||||
.collect::<Result<Vec<_>>>()
|
.collect::<Result<Vec<_>>>()
|
||||||
.with_context(|| format!("Included in {}", path.as_ref().display()))?;
|
.with_context(|| format!("Included in {}", path.as_ref().display()))?;
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ impl ScriptVar {
|
||||||
pub fn from_xml_element(xml: XmlElement) -> Result<Self> {
|
pub fn from_xml_element(xml: XmlElement) -> Result<Self> {
|
||||||
ensure_xml_tag_is!(xml, "script-var");
|
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();
|
let command = xml.only_child()?.as_text()?.text();
|
||||||
if let Ok(interval) = xml.attr("interval") {
|
if let Ok(interval) = xml.attr("interval") {
|
||||||
let interval = util::parse_duration(&interval)?;
|
let interval = util::parse_duration(&interval)?;
|
||||||
|
|
|
@ -1,8 +1,4 @@
|
||||||
use crate::{
|
use crate::{ensure_xml_tag_is, value::NumWithUnit, widgets::widget_node};
|
||||||
ensure_xml_tag_is,
|
|
||||||
value::{Coords, NumWithUnit},
|
|
||||||
widgets::widget_node,
|
|
||||||
};
|
|
||||||
use anyhow::*;
|
use anyhow::*;
|
||||||
use derive_more::*;
|
use derive_more::*;
|
||||||
use serde::{Deserialize, Serialize};
|
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>")?;
|
xml.child("reserve").ok().map(StrutDefinition::from_xml_element).transpose().context("Failed to parse <reserve>")?;
|
||||||
|
|
||||||
Ok(RawEwwWindowDefinition {
|
Ok(RawEwwWindowDefinition {
|
||||||
name: WindowName(xml.attr("name")?.to_owned()),
|
name: WindowName(xml.attr("name")?),
|
||||||
geometry: match xml.child("geometry") {
|
geometry: match xml.child("geometry") {
|
||||||
Ok(node) => EwwWindowGeometry::from_xml_element(node)?,
|
Ok(node) => EwwWindowGeometry::from_xml_element(node)?,
|
||||||
Err(_) => EwwWindowGeometry::default(),
|
Err(_) => EwwWindowGeometry::default(),
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#![feature(try_blocks)]
|
#![feature(try_blocks)]
|
||||||
#![feature(nll)]
|
#![feature(nll)]
|
||||||
|
|
||||||
|
|
||||||
extern crate gio;
|
extern crate gio;
|
||||||
extern crate gtk;
|
extern crate gtk;
|
||||||
#[cfg(feature = "wayland")]
|
#[cfg(feature = "wayland")]
|
||||||
|
@ -126,7 +127,7 @@ impl EwwPaths {
|
||||||
let daemon_id = base64::encode(format!("{}", config_dir.display()));
|
let daemon_id = base64::encode(format!("{}", config_dir.display()));
|
||||||
|
|
||||||
Ok(EwwPaths {
|
Ok(EwwPaths {
|
||||||
config_dir: config_dir.to_path_buf(),
|
config_dir,
|
||||||
log_file: std::env::var("XDG_CACHE_HOME")
|
log_file: std::env::var("XDG_CACHE_HOME")
|
||||||
.map(PathBuf::from)
|
.map(PathBuf::from)
|
||||||
.unwrap_or_else(|_| PathBuf::from(std::env::var("HOME").unwrap()).join(".cache"))
|
.unwrap_or_else(|_| PathBuf::from(std::env::var("HOME").unwrap()).join(".cache"))
|
||||||
|
|
12
src/util.rs
12
src/util.rs
|
@ -101,12 +101,12 @@ pub fn parse_duration(s: &str) -> Result<std::time::Duration> {
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
if s.ends_with("ms") {
|
if s.ends_with("ms") {
|
||||||
Ok(Duration::from_millis(s.trim_end_matches("ms").parse()?))
|
Ok(Duration::from_millis(s.trim_end_matches("ms").parse()?))
|
||||||
} else if s.ends_with("s") {
|
} else if s.ends_with('s') {
|
||||||
Ok(Duration::from_secs(s.trim_end_matches("s").parse()?))
|
Ok(Duration::from_secs(s.trim_end_matches('s').parse()?))
|
||||||
} else if s.ends_with("m") {
|
} else if s.ends_with('m') {
|
||||||
Ok(Duration::from_secs(s.trim_end_matches("m").parse::<u64>()? * 60))
|
Ok(Duration::from_secs(s.trim_end_matches('m').parse::<u64>()? * 60))
|
||||||
} else if s.ends_with("h") {
|
} else if s.ends_with('h') {
|
||||||
Ok(Duration::from_secs(s.trim_end_matches("h").parse::<u64>()? * 60 * 60))
|
Ok(Duration::from_secs(s.trim_end_matches('h').parse::<u64>()? * 60 * 60))
|
||||||
} else {
|
} else {
|
||||||
Err(anyhow!("unrecognized time format: {}", s))
|
Err(anyhow!("unrecognized time format: {}", s))
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
let parsed = match parser::parse(s) {
|
||||||
Ok((_, x)) => Ok(x),
|
Ok((_, x)) => Ok(x),
|
||||||
Err(nom::Err::Error(e) | nom::Err::Failure(e)) => Err(anyhow!(nom::error::convert_error(s, e))),
|
Err(nom::Err::Error(e) | nom::Err::Failure(e)) => Err(anyhow!(nom::error::convert_error(s, e))),
|
||||||
|
|
|
@ -23,7 +23,7 @@ where
|
||||||
fn parse_num(i: &str) -> IResult<&str, i32, VerboseError<&str>> {
|
fn parse_num(i: &str) -> IResult<&str, i32, VerboseError<&str>> {
|
||||||
alt((
|
alt((
|
||||||
map_res(digit1, |s: &str| s.parse::<i32>()),
|
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)
|
))(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)))
|
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)
|
complete(parse_expr)(i)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -131,7 +131,7 @@ fn parse_vec(a: String) -> Result<Vec<String>> {
|
||||||
let mut removed = 0;
|
let mut removed = 0;
|
||||||
for times_ran in 0..items.len() {
|
for times_ran in 0..items.len() {
|
||||||
// escapes `,` if there's a `\` before em
|
// 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();
|
items[times_ran - removed].pop();
|
||||||
let it = items.remove((times_ran + 1) - removed);
|
let it = items.remove((times_ran + 1) - removed);
|
||||||
items[times_ran - removed] += ",";
|
items[times_ran - removed] += ",";
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#![allow(clippy::option_map_unit_fn)]
|
||||||
use super::{run_command, BuilderArgs};
|
use super::{run_command, BuilderArgs};
|
||||||
use crate::{config, eww_state, resolve_block, value::AttrVal, widgets::widget_node};
|
use crate::{config, eww_state, resolve_block, value::AttrVal, widgets::widget_node};
|
||||||
use anyhow::*;
|
use anyhow::*;
|
||||||
|
@ -203,7 +204,7 @@ fn build_gtk_combo_box_text(bargs: &mut BuilderArgs) -> Result<gtk::ComboBoxText
|
||||||
prop(onchange: as_string) {
|
prop(onchange: as_string) {
|
||||||
let old_id = on_change_handler_id.replace(Some(
|
let old_id = on_change_handler_id.replace(Some(
|
||||||
gtk_widget.connect_changed(move |gtk_widget| {
|
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));
|
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) {
|
prop(onchange: as_string) {
|
||||||
let old_id = on_change_handler_id.replace(Some(
|
let old_id = on_change_handler_id.replace(Some(
|
||||||
gtk_widget.connect_color_activated(move |_a, color| {
|
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));
|
old_id.map(|id| gtk_widget.disconnect(id));
|
||||||
|
|
|
@ -91,8 +91,8 @@ impl WidgetNode for Generic {
|
||||||
window_name: &WindowName,
|
window_name: &WindowName,
|
||||||
widget_definitions: &HashMap<String, WidgetDefinition>,
|
widget_definitions: &HashMap<String, WidgetDefinition>,
|
||||||
) -> Result<gtk::Widget> {
|
) -> Result<gtk::Widget> {
|
||||||
Ok(crate::widgets::build_builtin_gtk_widget(eww_state, window_name, widget_definitions, &self)?
|
crate::widgets::build_builtin_gtk_widget(eww_state, window_name, widget_definitions, &self)?
|
||||||
.with_context(|| format!("Unknown widget '{}'", self.get_name()))?)
|
.with_context(|| format!("Unknown widget '{}'", self.get_name()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue