commit | 56e2703977022b768467fd463c113c80711615a3 | [log] [tgz] |
---|---|---|
author | Radu <[email protected]> | Mon Nov 25 16:55:08 2024 +0000 |
committer | Radu <[email protected]> | Mon Nov 25 17:08:54 2024 +0000 |
tree | f0cd8d5840ac92bb8a93bc0348bf7e19f5084b32 | |
parent | 32c26189da299be24e83c8051e9d50d577188bc8 [diff] |
Add librusb_platform variant Added the librusb platform variant that uses the liblibusb1_sys_platform library. This dependency, in turn, uses libusb_platform that enables listening to hotplug events. This should be used only by programs running at OS-level. Bug: 376046775 Test: m librusb; m librusb_platform, - manually test librusb_platform on device Change-Id: I0d1489aa0ee41dbb4194be4128f210cec0a6e4fb
This crate provides a safe wrapper around the native libusb
library. It applies the RAII pattern and Rust lifetimes to ensure safe usage of all libusb
functionality. The RAII pattern ensures that all acquired resources are released when they're no longer needed, and Rust lifetimes ensure that resources are released in a proper order.
To use rusb no extra setup is required as rusb will automatically download the source for libusb and build it.
However if building libusb fails you can also try setting up the native libusb
library where it can be found by pkg-config
or vcpkg
.
All systems supported by the native libusb
library are also supported by the libusb
crate. It's been tested on Linux, OS X, and Windows.
The rusb
crate can be used when cross-compiling to a foreign target. Details on how to cross-compile rusb
are explained in the libusb1-sys
crate's README.
Add rusb
as a dependency in Cargo.toml
:
[dependencies] rusb = "0.9"
Import the rusb
crate. The starting point for nearly all rusb
functionality is to create a context object. With a context object, you can list devices, read their descriptors, open them, and communicate with their endpoints:
fn main() { for device in rusb::devices().unwrap().iter() { let device_desc = device.device_descriptor().unwrap(); println!("Bus {:03} Device {:03} ID {:04x}:{:04x}", device.bus_number(), device.address(), device_desc.vendor_id(), device_desc.product_id()); } }
Distributed under the MIT License.
If you link native libusb
(by example using vendored
features) library statically then you must follow GNU LGPL from libusb.