Skip to main content

LinuxUsbWatcher

Struct LinuxUsbWatcher 

Source
pub struct LinuxUsbWatcher { /* private fields */ }
Expand description

Linux-specific USB device watcher implementation.

This watcher uses the Linux sysfs filesystem (/sys/bus/usb/devices) to monitor USB device connections and disconnections. It polls the filesystem periodically to detect changes and sends events through the provided channel.

Device handles are provided for each detected device, including sysfs path. Future versions may detect device nodes (e.g., /dev/ttyUSB0).

Implementations§

Source§

impl LinuxUsbWatcher

Source

pub fn new(tx: Sender<UsbDeviceInfo>) -> Self

Creates a new Linux USB watcher.

§Arguments
  • tx - Channel sender for broadcasting USB device events
§Returns

A new LinuxUsbWatcher instance

Source

pub async fn start_monitoring(&self) -> Result<(), String>

Starts monitoring USB devices on Linux.

This method continuously polls the /sys/bus/usb/devices directory to detect USB device connection and disconnection events. It maintains a map of known devices and compares against current devices to identify changes.

§Returns

Returns Ok(()) if monitoring stops gracefully, or Err(String) if an error occurs during monitoring.

§Errors

Returns an error if:

  • The USB devices directory is not accessible
  • File system operations fail
  • Device information parsing fails

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.