20 releases

0.9.4 Apr 27, 2024
0.9.3 Aug 25, 2023
0.9.2 Mar 26, 2023
0.9.1 Apr 11, 2022
0.4.0 Jul 28, 2019

#11 in Hardware support

Download history 26245/week @ 2024-07-19 25987/week @ 2024-07-26 27396/week @ 2024-08-02 27667/week @ 2024-08-09 23729/week @ 2024-08-16 25717/week @ 2024-08-23 24733/week @ 2024-08-30 24147/week @ 2024-09-06 20441/week @ 2024-09-13 22943/week @ 2024-09-20 24851/week @ 2024-09-27 27584/week @ 2024-10-04 25118/week @ 2024-10-11 27540/week @ 2024-10-18 27639/week @ 2024-10-25 27044/week @ 2024-11-01

112,499 downloads per month
Used in 151 crates (99 directly)

MIT license

1MB
25K SLoC

C 17K SLoC // 0.3% comments Rust 6K SLoC // 0.0% comments C++ 1.5K SLoC // 0.1% comments Visual Studio Project 563 SLoC Visual Studio Solution 541 SLoC Automake 75 SLoC PowerShell 14 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