commit | d25052c0af9fa14192cdb4e3deaed15a3bec3979 | [log] [tgz] |
---|---|---|
author | James Farrell <[email protected]> | Tue Dec 03 20:15:31 2024 +0000 |
committer | Automerger Merge Worker <[email protected]> | Tue Dec 03 20:15:31 2024 +0000 |
tree | c19333eb03952cc2a09f98f975727b84e5d6e296 | |
parent | 02b8e125679bc14f4f3c51ea453f9544bb7c7899 [diff] | |
parent | 856c094f5dedc25353a0b2b41e55afd41397d4b8 [diff] |
Migrate 9 newly imported crates to monorepo am: 856c094f5d Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/rusb/+/3388337 Change-Id: Iddf362b0f3f5ac1d9d53153ed94e3f2126f48256 Signed-off-by: Automerger Merge Worker <[email protected]>
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.