Skip to content

Commit

Permalink
Add derive Debug, closing #17
Browse files Browse the repository at this point in the history
  • Loading branch information
jiegec committed Oct 26, 2024
1 parent 066aeb1 commit 94d6749
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/cdc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use super::*;

/// A handler of a CDC ACM(Abstract Control Model)
#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct UsbCdcAcmHandler {
pub tx_buffer: Vec<u8>,
}
Expand Down
6 changes: 3 additions & 3 deletions src/device.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::*;
use rusb::Version as rusbVersion;

#[derive(Clone, Default)]
#[derive(Clone, Default, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Version {
pub major: u8,
Expand Down Expand Up @@ -37,7 +37,7 @@ impl From<u16> for Version {
}

/// Represent a USB device
#[derive(Clone, Default)]
#[derive(Clone, Default, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize))]
pub struct UsbDevice {
pub path: String,
Expand Down Expand Up @@ -529,7 +529,7 @@ impl UsbDevice {
}

/// A handler for URB targeting the device
pub trait UsbDeviceHandler {
pub trait UsbDeviceHandler: std::fmt::Debug {
/// Handle a URB(USB Request Block) targeting at this device
///
/// When the lower 4 bits of `bmRequestType` is zero and the URB is not handled by the library, this function is called.
Expand Down
6 changes: 3 additions & 3 deletions src/hid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ use super::*;
// HID 1.11: https://www.usb.org/sites/default/files/documents/hid1_11.pdf
// HID Usage Tables 1.12: https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf

#[derive(Clone)]
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
enum UsbHidKeyboardHandlerState {
Idle,
KeyDown,
}

/// A handler of a HID keyboard
#[derive(Clone)]
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct UsbHidKeyboardHandler {
pub report_descriptor: Vec<u8>,
Expand All @@ -24,7 +24,7 @@ pub struct UsbHidKeyboardHandler {
/// A report of a HID keyboard
///
/// For definition of key codes, see [HID Usage Tables](https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf)
#[derive(Clone)]
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct UsbHidKeyboardReport {
/// Key modifier
Expand Down
20 changes: 18 additions & 2 deletions src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use super::*;

/// A handler to pass requests to a rusb USB device of the host
#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct RusbUsbHostInterfaceHandler {
handle: Arc<Mutex<DeviceHandle<GlobalContext>>>,
}
Expand Down Expand Up @@ -93,7 +93,7 @@ impl UsbInterfaceHandler for RusbUsbHostInterfaceHandler {
}

/// A handler to pass requests to a USB device of the host
#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct RusbUsbHostDeviceHandler {
handle: Arc<Mutex<DeviceHandle<GlobalContext>>>,
}
Expand Down Expand Up @@ -155,6 +155,14 @@ pub struct NusbUsbHostInterfaceHandler {
handle: Arc<Mutex<nusb::Interface>>,
}

impl std::fmt::Debug for NusbUsbHostInterfaceHandler {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("NusbUsbHostInterfaceHandler")
.field("handle", &"Opaque")
.finish()
}
}

impl NusbUsbHostInterfaceHandler {
pub fn new(handle: Arc<Mutex<nusb::Interface>>) -> Self {
Self { handle }
Expand Down Expand Up @@ -231,6 +239,14 @@ pub struct NusbUsbHostDeviceHandler {
handle: Arc<Mutex<nusb::Device>>,
}

impl std::fmt::Debug for NusbUsbHostDeviceHandler {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("NusbUsbHostDeviceHandler")
.field("handle", &"Opaque")
.finish()
}
}

impl NusbUsbHostDeviceHandler {
pub fn new(handle: Arc<Mutex<nusb::Device>>) -> Self {
Self { handle }
Expand Down
4 changes: 2 additions & 2 deletions src/interface.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::*;

/// Represent a USB interface
#[derive(Clone)]
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize))]
pub struct UsbInterface {
pub interface_class: u8,
Expand All @@ -16,7 +16,7 @@ pub struct UsbInterface {
}

/// A handler of a custom usb interface
pub trait UsbInterfaceHandler {
pub trait UsbInterfaceHandler: std::fmt::Debug {
/// Return the class specific descriptor which is inserted between interface descriptor and endpoint descriptor
fn get_class_specific_descriptor(&self) -> Vec<u8>;

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub use util::*;
use crate::usbip_protocol::{UsbIpResponse, USBIP_RET_SUBMIT, USBIP_RET_UNLINK};

/// Main struct of a USB/IP server
#[derive(Default)]
#[derive(Default, Debug)]
pub struct UsbIpServer {
available_devices: RwLock<Vec<UsbDevice>>,
used_devices: RwLock<HashMap<String, UsbDevice>>,
Expand Down

0 comments on commit 94d6749

Please sign in to comment.