From 2339249dc3566bc862e663e3d155c827915ff634 Mon Sep 17 00:00:00 2001 From: Crend King <975235+CrendKing@users.noreply.github.com> Date: Mon, 10 Jun 2024 23:56:17 -0700 Subject: [PATCH] Use if_chain as reminder for https://github.com/rust-lang/rust/issues/53667 --- Cargo.toml | 1 + src/config.rs | 7 +++++-- src/main.rs | 18 +++++++++++------- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index da2f512..b39c83f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ edition = '2021' duration-str = '*' enigo = { version = '*', default-features = false, features = ['serde', 'wayland'] } gilrs = { version = '*', features = ['serde'] } +if_chain = '*' lazy_static = '*' serde = '*' shlex = '*' diff --git a/src/config.rs b/src/config.rs index dbeab42..424e7cf 100644 --- a/src/config.rs +++ b/src/config.rs @@ -2,6 +2,7 @@ use std::collections::HashMap; use std::time::Duration; use duration_str::deserialize_duration; +use if_chain::if_chain; #[derive(Debug, serde::Deserialize)] #[serde(rename_all = "snake_case")] @@ -49,8 +50,10 @@ impl Config { return Err("Trigger zone smaller than dead zone"); } - if let Some(activator) = &self.alternative_activator { - if self.main.contains_key(activator) { + if_chain! { + if let Some(activator) = &self.alternative_activator; + if self.main.contains_key(activator); + then { return Err("Activator for alternative set is remapped"); } } diff --git a/src/main.rs b/src/main.rs index 9cf7b82..eeee82e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,6 +5,7 @@ use std::sync::atomic::{AtomicBool, Ordering}; use enigo::{Direction, Enigo, Keyboard, Mouse}; use gilrs::{Axis, Event, EventType, Gilrs}; +use if_chain::if_chain; use lazy_static::lazy_static; use crate::atomic_f32::AtomicF32; @@ -45,8 +46,10 @@ lazy_static! { } fn press_input(input_name: &str, is_press_down: bool) { - if let Some(activator) = &CONFIG.alternative_activator { - if input_name == activator.as_ref() { + if_chain! { + if let Some(activator) = &CONFIG.alternative_activator; + if input_name == activator.as_ref(); + then { IS_ALTERNATIVE_ACTIVE.store(is_press_down, Ordering::Relaxed); return; } @@ -110,11 +113,12 @@ fn press_input(input_name: &str, is_press_down: bool) { .unwrap(); } Remap::Command(cmdline) => { - if is_press_down { - if let Some(components) = shlex::split(cmdline) { - if !components.is_empty() { - std::process::Command::new(&components[0]).args(&components[1..]).spawn().unwrap(); - } + if_chain! { + if is_press_down; + if let Some(components) = shlex::split(cmdline); + if !components.is_empty(); + then { + std::process::Command::new(&components[0]).args(&components[1..]).spawn().unwrap(); } } }