mirror of
https://github.com/htrefil/rkvm.git
synced 2025-01-19 10:26:13 +01:00
Fix clippy warnings
This commit is contained in:
parent
bc6e35bdcf
commit
ea401ba998
5 changed files with 31 additions and 14 deletions
5
Cargo.lock
generated
5
Cargo.lock
generated
|
@ -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",
|
||||||
|
|
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -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));
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue