Skip to content

Commit

Permalink
clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Pinot committed Apr 19, 2022
1 parent 4ec229d commit 8a00b85
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
20 changes: 13 additions & 7 deletions src/hid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ use usb_device::UsbError;
const SPECIFICATION_RELEASE: u16 = 0x111;
const INTERFACE_CLASS_HID: u8 = 0x03;

pub struct Error;

#[derive(Clone, Copy, Debug, PartialEq)]
#[repr(u8)]
pub enum Subclass {
Expand Down Expand Up @@ -90,10 +92,14 @@ pub trait HidDevice {

fn report_descriptor(&self) -> &[u8];

fn set_report(&mut self, report_type: ReportType, report_id: u8, data: &[u8])
-> Result<(), ()>;
fn set_report(
&mut self,
report_type: ReportType,
report_id: u8,
data: &[u8],
) -> Result<(), Error>;

fn get_report(&mut self, report_type: ReportType, report_id: u8) -> Result<&[u8], ()>;
fn get_report(&mut self, report_type: ReportType, report_id: u8) -> Result<&[u8], Error>;
}

pub struct HidClass<'a, B: UsbBus, D: HidDevice> {
Expand All @@ -118,7 +124,7 @@ impl<B: UsbBus, D: HidDevice> HidClass<'_, B, D> {
&mut self.device
}

pub fn write(&mut self, data: &[u8]) -> Result<usize, ()> {
pub fn write(&mut self, data: &[u8]) -> Result<usize, Error> {
if self.expect_interrupt_in_complete {
return Ok(0);
}
Expand All @@ -130,7 +136,7 @@ impl<B: UsbBus, D: HidDevice> HidClass<'_, B, D> {
match self.endpoint_interrupt_in.write(data) {
Ok(count) => Ok(count),
Err(UsbError::WouldBlock) => Ok(0),
Err(_) => Err(()),
Err(_) => Err(Error),
}
}

Expand All @@ -140,7 +146,7 @@ impl<B: UsbBus, D: HidDevice> HidClass<'_, B, D> {
let report_type = ReportType::from(report_type);
match self.device.get_report(report_type, report_id) {
Ok(data) => xfer.accept_with(data).ok(),
Err(()) => xfer.reject().ok(),
Err(Error) => xfer.reject().ok(),
};
}

Expand All @@ -150,7 +156,7 @@ impl<B: UsbBus, D: HidDevice> HidClass<'_, B, D> {
let report_type = ReportType::from(report_type);
match self.device.set_report(report_type, report_id, xfer.data()) {
Ok(()) => xfer.accept().ok(),
Err(()) => xfer.reject().ok(),
Err(Error) => xfer.reject().ok(),
};
}

Expand Down
10 changes: 5 additions & 5 deletions src/keyboard.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Keyboard HID device implementation.
use crate::hid::{HidDevice, Protocol, ReportType, Subclass};
use crate::hid::{self, HidDevice, Protocol, ReportType, Subclass};
use crate::key_code::KbHidReport;

/// A trait to manage keyboard LEDs.
Expand Down Expand Up @@ -103,10 +103,10 @@ impl<L: Leds> HidDevice for Keyboard<L> {
REPORT_DESCRIPTOR
}

fn get_report(&mut self, report_type: ReportType, _report_id: u8) -> Result<&[u8], ()> {
fn get_report(&mut self, report_type: ReportType, _report_id: u8) -> Result<&[u8], hid::Error> {
match report_type {
ReportType::Input => Ok(self.report.as_bytes()),
_ => Err(()),
_ => Err(hid::Error),
}
}

Expand All @@ -115,7 +115,7 @@ impl<L: Leds> HidDevice for Keyboard<L> {
report_type: ReportType,
report_id: u8,
data: &[u8],
) -> Result<(), ()> {
) -> Result<(), hid::Error> {
if report_type == ReportType::Output && report_id == 0 && data.len() == 1 {
let d = data[0];
self.leds.num_lock(d & 1 != 0);
Expand All @@ -125,6 +125,6 @@ impl<L: Leds> HidDevice for Keyboard<L> {
self.leds.kana(d & 1 << 4 != 0);
return Ok(());
}
Err(())
Err(hid::Error)
}
}

0 comments on commit 8a00b85

Please sign in to comment.