7 releases

✓ Uses Rust 2018 edition

0.5.5 Jan 23, 2020
0.5.4 Dec 27, 2019
0.5.2 Sep 12, 2019
0.5.1 Aug 12, 2019
0.4.0 Jul 28, 2019

#7 in Hardware support

Download history 179/week @ 2019-12-14 260/week @ 2019-12-21 1613/week @ 2019-12-28 1303/week @ 2020-01-04 635/week @ 2020-01-11 831/week @ 2020-01-18 484/week @ 2020-01-25 522/week @ 2020-02-01 481/week @ 2020-02-08 326/week @ 2020-02-15 467/week @ 2020-02-22 1076/week @ 2020-02-29 812/week @ 2020-03-07 392/week @ 2020-03-14 798/week @ 2020-03-21 572/week @ 2020-03-28

1,961 downloads per month
Used in 14 crates (9 directly)

MIT license

175KB
4.5K 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.5"

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

Contributors

License

Copyright © 2015 David Cuddeback

Distributed under the MIT License.

Dependencies

~510–710KB