Getting details of connected USB devices (project)
In this section, we will demonstrate an example of working with devices in Rust. The example chosen is to display details of all connected USB devices of a computer. We'll be using libusb
, a C library that helps to interact with USB devices. The libusb
crate in Rust is a safe wrapper around the C libusb
library. Let's first look at the design.
Designing the project
Here is how this would work:
- When a USB device is plugged into a computer, the electrical signals on the computer bus trigger the USB controller (hardware device) on the computer.
- The USB controller raises an interrupt on the CPU, which then executes the interrupt handler registered for that interrupt in the kernel.
- When a call is made from the Rust program through the Rust
libusb
wrapper crate, the call is routed to thelibusb
C library, which in turn makes a system call on the kernel to read the device file corresponding to the USB device...