Bug: 376647800

Clone this repo:
  1. d25052c Migrate 9 newly imported crates to monorepo am: 856c094f5d by James Farrell · 5 months ago main aml_ads_351420000 aml_ase_351412000 aml_con_351412000 aml_ext_351423040 aml_hef_351420080 aml_mpr_351416060 aml_odp_351421000 aml_sdk_351415000 aml_sta_351416000 aml_tet_351415080 aml_tz6_351400020
  2. 856c094 Migrate 9 newly imported crates to monorepo by James Farrell · 5 months ago
  3. 02b8e12 Add librusb_platform variant am: 56e2703977 by Radu · 5 months ago
  4. e8e0c34 Merge remote-tracking branch 'origin/upstream' am: 32c26189da by Frank Piva · 5 months ago
  5. 56e2703 Add librusb_platform variant by Radu · 5 months ago

Rusb

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.

Dependencies

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.

Cross-Compiling

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.

Usage

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());
    }
}

License

Distributed under the MIT License.

License note.

If you link native libusb (by example using vendored features) library statically then you must follow GNU LGPL from libusb.