16 unstable releases (5 breaking)

0.9.0 Sep 10, 2021
0.8.1 Jun 3, 2021
0.8.0 Feb 25, 2021
0.6.5 Oct 26, 2020
0.4.0 Jul 28, 2019

#5 in Hardware support

Download history 1449/week @ 2021-05-29 1433/week @ 2021-06-05 1527/week @ 2021-06-12 1352/week @ 2021-06-19 1300/week @ 2021-06-26 1431/week @ 2021-07-03 1425/week @ 2021-07-10 1186/week @ 2021-07-17 1707/week @ 2021-07-24 1422/week @ 2021-07-31 1205/week @ 2021-08-07 1439/week @ 2021-08-14 1384/week @ 2021-08-21 1419/week @ 2021-08-28 1518/week @ 2021-09-04 1943/week @ 2021-09-11

5,971 downloads per month
Used in 55 crates (30 directly)

MIT license

1.5MB
28K SLoC

C 16K SLoC // 0.3% comments Rust 6K SLoC // 0.0% comments Visual Studio Project 4.5K SLoC C++ 1K SLoC // 0.0% comments Visual Studio Solution 753 SLoC Automake 67 SLoC

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.

Dependencies