7 unstable releases

Uses old Rust 2015

0.3.0 Sep 10, 2016
0.2.2 Nov 5, 2015
0.2.1 Oct 18, 2015
0.1.1 May 24, 2015
0.0.2 Mar 29, 2015

#5 in #libusb

Download history 427/week @ 2021-01-21 454/week @ 2021-01-28 475/week @ 2021-02-04 397/week @ 2021-02-11 366/week @ 2021-02-18 472/week @ 2021-02-25 417/week @ 2021-03-04 338/week @ 2021-03-11 435/week @ 2021-03-18 237/week @ 2021-03-25 321/week @ 2021-04-01 414/week @ 2021-04-08 450/week @ 2021-04-15 317/week @ 2021-04-22 251/week @ 2021-04-29 219/week @ 2021-05-06

1,512 downloads per month
Used in 22 crates (20 directly)

MIT license

150KB
3K SLoC

Libusb

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

In order to use the libusb crate, you must have the native libusb library installed where it can be found by pkg-config.

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 libusb crate can be used when cross-compiling to a foreign target. Details on how to cross-compile libusb are explained in the libusb-sys crate's README.

Usage

Add libusb as a dependency in Cargo.toml:

[dependencies]
libusb = "0.3"

Import the libusb crate. The starting point for nearly all libusb 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:

extern crate libusb;

fn main() {
    let mut context = libusb::Context::new().unwrap();

    for mut device in context.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

~175KB