Fix clippy warnings

This commit is contained in:
htrefil 2020-11-12 18:09:44 +01:00
parent bc6e35bdcf
commit ea401ba998
5 changed files with 31 additions and 14 deletions

5
Cargo.lock generated
View file

@ -375,8 +375,9 @@ checksum = "3c1ad908cc71012b7bea4d0c53ba96a8cba9962f048fa68d143376143d863b7a"
[[package]] [[package]]
name = "inotify" name = "inotify"
version = "0.9.0" version = "0.9.1"
source = "git+https://github.com/htrefil/inotify/#3838a9f0d080a6e0d41ad5dc1bcaa90a8828232b" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04c6848dfb1580647ab039713282cdd1ab2bfb47b60ecfb598e22e60e3baf3f8"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"futures-core", "futures-core",

View file

@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize}; 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 { pub enum Button {
A, A,
B, B,
@ -254,7 +255,7 @@ impl Button {
use Button::*; use Button::*;
// This is generated from linux headers, some patterns are unreachable, and we don't care. // 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 { let button = match code {
0x0130 => A, 0x0130 => A,
0x0131 => B, 0x0131 => B,
@ -385,3 +386,12 @@ impl PartialEq for Button {
self.to_raw() == other.to_raw() self.to_raw() == other.to_raw()
} }
} }
impl Hash for Button {
fn hash<H>(&self, state: &mut H)
where
H: Hasher,
{
self.to_raw().hash(state)
}
}

View file

@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize}; 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 { pub enum Key {
A, A,
Ab, Ab,
@ -1487,3 +1488,12 @@ impl PartialEq for Key {
self.to_raw() == other.to_raw() self.to_raw() == other.to_raw()
} }
} }
impl Hash for Key {
fn hash<H>(&self, state: &mut H)
where
H: Hasher,
{
self.to_raw().hash(state)
}
}

View file

@ -12,7 +12,7 @@ pub struct EventWriter {
impl EventWriter { impl EventWriter {
pub async fn new() -> Result<Self, Error> { pub async fn new() -> Result<Self, Error> {
tokio::task::spawn_blocking(|| Self::new_sync()).await? tokio::task::spawn_blocking(Self::new_sync).await?
} }
fn new_sync() -> Result<Self, Error> { fn new_sync() -> Result<Self, Error> {
@ -109,7 +109,7 @@ unsafe fn setup_evdev(evdev: *mut libevdev) -> Result<(), Error> {
return Err(Error::from_raw_os_error(-ret)); 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()); let ret = glue::libevdev_enable_event_code(evdev, r#type, code, std::ptr::null_mut());
if ret < 0 { if ret < 0 {
return Err(Error::from_raw_os_error(-ret)); return Err(Error::from_raw_os_error(-ret));

View file

@ -101,7 +101,7 @@ async fn run(
.await .await
.err() .err()
.map(|err| format!(" ({})", err)) .map(|err| format!(" ({})", err))
.unwrap_or(String::new()); .unwrap_or_else(String::new);
log::info!("{}: disconnected{}", address, message); log::info!("{}: disconnected{}", address, message);
}); });
} }
@ -121,17 +121,13 @@ async fn run(
let event = event?; let event = event?;
if let Event::Key { direction, kind: KeyKind::Key(key) } = event { if let Event::Key { direction, kind: KeyKind::Key(key) } = event {
if let Some(state) = key_states.get_mut(&key) { if let Some(state) = key_states.get_mut(&key) {
*state = if direction == Direction::Down { *state = direction == Direction::Down;
true
} else {
false
};
} }
} }
// TODO: This won't work with multiple keys. // TODO: This won't work with multiple keys.
if key_states.iter().filter(|(_, state)| **state).count() == key_states.len() { 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; *state = false;
} }