diff --git a/Cargo.lock b/Cargo.lock index 0827394..3ae264e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -375,8 +375,9 @@ checksum = "3c1ad908cc71012b7bea4d0c53ba96a8cba9962f048fa68d143376143d863b7a" [[package]] name = "inotify" -version = "0.9.0" -source = "git+https://github.com/htrefil/inotify/#3838a9f0d080a6e0d41ad5dc1bcaa90a8828232b" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04c6848dfb1580647ab039713282cdd1ab2bfb47b60ecfb598e22e60e3baf3f8" dependencies = [ "bitflags", "futures-core", diff --git a/input/src/event/button.rs b/input/src/event/button.rs index 7db22d4..a08732f 100644 --- a/input/src/event/button.rs +++ b/input/src/event/button.rs @@ -1,6 +1,7 @@ use serde::{Deserialize, Serialize}; +use std::hash::{Hash, Hasher}; -#[derive(Clone, Copy, Debug, Eq, Serialize, Deserialize, Hash)] +#[derive(Clone, Copy, Debug, Eq, Serialize, Deserialize)] pub enum Button { A, B, @@ -254,7 +255,7 @@ impl Button { use Button::*; // This is generated from linux headers, some patterns are unreachable, and we don't care. - #[allow(unreachable_patterns)] + #[allow(unreachable_patterns, clippy::match_overlapping_arm)] let button = match code { 0x0130 => A, 0x0131 => B, @@ -385,3 +386,12 @@ impl PartialEq for Button { self.to_raw() == other.to_raw() } } + +impl Hash for Button { + fn hash(&self, state: &mut H) + where + H: Hasher, + { + self.to_raw().hash(state) + } +} diff --git a/input/src/event/key.rs b/input/src/event/key.rs index 49538e6..fc5fd98 100644 --- a/input/src/event/key.rs +++ b/input/src/event/key.rs @@ -1,6 +1,7 @@ use serde::{Deserialize, Serialize}; +use std::hash::{Hash, Hasher}; -#[derive(Clone, Copy, Debug, Eq, Serialize, Deserialize, Hash)] +#[derive(Clone, Copy, Debug, Eq, Serialize, Deserialize)] pub enum Key { A, Ab, @@ -1487,3 +1488,12 @@ impl PartialEq for Key { self.to_raw() == other.to_raw() } } + +impl Hash for Key { + fn hash(&self, state: &mut H) + where + H: Hasher, + { + self.to_raw().hash(state) + } +} diff --git a/input/src/event_writer.rs b/input/src/event_writer.rs index ab4d0a7..46ac181 100644 --- a/input/src/event_writer.rs +++ b/input/src/event_writer.rs @@ -12,7 +12,7 @@ pub struct EventWriter { impl EventWriter { pub async fn new() -> Result { - tokio::task::spawn_blocking(|| Self::new_sync()).await? + tokio::task::spawn_blocking(Self::new_sync).await? } fn new_sync() -> Result { @@ -109,7 +109,7 @@ unsafe fn setup_evdev(evdev: *mut libevdev) -> Result<(), Error> { return Err(Error::from_raw_os_error(-ret)); } - for code in codes.iter().cloned().flat_map(|code| code) { + for code in codes.iter().cloned().flatten() { let ret = glue::libevdev_enable_event_code(evdev, r#type, code, std::ptr::null_mut()); if ret < 0 { return Err(Error::from_raw_os_error(-ret)); diff --git a/server/src/main.rs b/server/src/main.rs index e62202b..56efe84 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -101,7 +101,7 @@ async fn run( .await .err() .map(|err| format!(" ({})", err)) - .unwrap_or(String::new()); + .unwrap_or_else(String::new); log::info!("{}: disconnected{}", address, message); }); } @@ -121,17 +121,13 @@ async fn run( let event = event?; if let Event::Key { direction, kind: KeyKind::Key(key) } = event { if let Some(state) = key_states.get_mut(&key) { - *state = if direction == Direction::Down { - true - } else { - false - }; + *state = direction == Direction::Down; } } // TODO: This won't work with multiple keys. if key_states.iter().filter(|(_, state)| **state).count() == key_states.len() { - for (_, state) in &mut key_states { + for state in key_states.values_mut() { *state = false; }