From c01ba9f44829c6fe8f35befb731b671df82260dd Mon Sep 17 00:00:00 2001 From: Wilf Silver Date: Sat, 14 May 2022 15:07:12 +0100 Subject: [PATCH] Format code --- crates/eww/src/app.rs | 44 ++++++++++++++++++++++--------- crates/eww/src/opts.rs | 8 ++---- crates/yuck/src/config/monitor.rs | 4 +-- 3 files changed, 36 insertions(+), 20 deletions(-) diff --git a/crates/eww/src/app.rs b/crates/eww/src/app.rs index 31e6d288..00fef726 100644 --- a/crates/eww/src/app.rs +++ b/crates/eww/src/app.rs @@ -19,7 +19,7 @@ use std::{ cell::RefCell, collections::{HashMap, HashSet}, rc::Rc, - str::FromStr + str::FromStr, }; use tokio::sync::mpsc::UnboundedSender; use yuck::{ @@ -116,8 +116,7 @@ impl WindowInitiator { pub fn extract_value_from_args(name: &str, args: &mut Vec<(VarName, DynVal)>) -> Result, T::Err> { let var_name = name.to_string(); - let pos = args.iter() - .position(|(n,_)| n.0 == var_name); + let pos = args.iter().position(|(n, _)| n.0 == var_name); if pos.is_some() { let (_, val) = args.remove(pos.unwrap()); @@ -148,7 +147,11 @@ impl WindowInitiator { if attr.optional { local_variables.insert(name, DynVal::from(String::new())); } else { - return Err(anyhow!("Error, {} was required when creating {} but was not given", attr.name, self.config_name)); + return Err(anyhow!( + "Error, {} was required when creating {} but was not given", + attr.name, + self.config_name + )); } } } @@ -156,11 +159,12 @@ impl WindowInitiator { if local_variables.len() != window_def.expected_args.len() { let unexpected_vars: Vec = local_variables .iter() - .filter_map(|(n,_)| if !expected_args.contains(&n.0) { Some(n.clone()) } else { None }) + .filter_map(|(n, _)| if !expected_args.contains(&n.0) { Some(n.clone()) } else { None }) .collect(); - return Err(anyhow!("'{}' {} unexpectedly defined when creating window {}", + return Err(anyhow!( + "'{}' {} unexpectedly defined when creating window {}", unexpected_vars.join(","), - if unexpected_vars.len() == 1 { "was" } else { "were"}, + if unexpected_vars.len() == 1 { "was" } else { "were" }, self.config_name )); } @@ -278,9 +282,16 @@ impl App { self.close_window(id) } else { log::debug!("Config: {}, id: {}", config_name, id); - let window_args: Vec<(VarName, DynVal)> = args.iter() - .filter_map(|(win_id,n,v)| if win_id == "" || win_id == id { Some((n.clone(), v.clone())) } else { None }) - .collect(); + let window_args: Vec<(VarName, DynVal)> = + args.iter() + .filter_map(|(win_id, n, v)| { + if win_id == "" || win_id == id { + Some((n.clone(), v.clone())) + } else { + None + } + }) + .collect(); self.open_window(id, &WindowInitiator::new_from_args(config_name.clone(), window_args)?) } }) @@ -303,7 +314,10 @@ impl App { let is_open = self.open_windows.contains_key(&id); let result = if !is_open { - self.open_window(&id, &WindowInitiator::new(window_name, pos, size, monitor, anchor, args.unwrap_or(Vec::new()))) + self.open_window( + &id, + &WindowInitiator::new(window_name, pos, size, monitor, anchor, args.unwrap_or(Vec::new())), + ) } else if should_toggle { self.close_window(&id) } else { @@ -609,7 +623,13 @@ fn initialize_window( window.show_all(); - Ok(EwwWindow { instance_id: instance_id.to_string(), name: window_def.name.clone(), gtk_window: window, scope_index: window_scope, destroy_event_handler_id: None }) + Ok(EwwWindow { + instance_id: instance_id.to_string(), + name: window_def.name.clone(), + gtk_window: window, + scope_index: window_scope, + destroy_event_handler_id: None, + }) } /// Apply the provided window-positioning rules to the window. diff --git a/crates/eww/src/opts.rs b/crates/eww/src/opts.rs index 41d00905..bda71407 100644 --- a/crates/eww/src/opts.rs +++ b/crates/eww/src/opts.rs @@ -198,9 +198,7 @@ impl From for Opt { } fn parse_window_config_and_id(s: &str) -> Result<(String, String)> { - let (name, id) = s - .split_once(':') - .unwrap_or((s, s)); + let (name, id) = s.split_once(':').unwrap_or((s, s)); Ok((name.to_string(), id.to_string())) } @@ -209,9 +207,7 @@ fn parse_window_id_args(s: &str) -> Result<(String, VarName, DynVal)> { // Parse the = first so we know if an id has not been given let (name, value) = parse_var_update_arg(s)?; - let (id, var_name) = (&name.0) - .split_once(':') - .unwrap_or((&"", &name.0)); + let (id, var_name) = (&name.0).split_once(':').unwrap_or((&"", &name.0)); Ok((id.to_string(), var_name.into(), value)) } diff --git a/crates/yuck/src/config/monitor.rs b/crates/yuck/src/config/monitor.rs index 5a5306fb..461dd133 100644 --- a/crates/yuck/src/config/monitor.rs +++ b/crates/yuck/src/config/monitor.rs @@ -1,7 +1,7 @@ use std::{convert::Infallible, fmt, str}; use serde::{Deserialize, Serialize}; -use simplexpr::dynval::{DynVal, ConversionError}; +use simplexpr::dynval::{ConversionError, DynVal}; /// The type of the identifier used to select a monitor #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] @@ -13,7 +13,7 @@ pub enum MonitorIdentifier { impl MonitorIdentifier { pub fn from_dynval(val: &DynVal) -> Result { match val.as_i32() { - Ok(x) => Ok(MonitorIdentifier::Numeric(x)), + Ok(x) => Ok(MonitorIdentifier::Numeric(x)), Err(_) => Ok(MonitorIdentifier::Name(val.as_string()?)), } }