#usb #bindings #libusb #hardware

sys libusb-src

FFI bindings for libusb. Can be easily cross compiled.

2 stable releases

1.27.0+1.0.26 Oct 9, 2023
1.26.2 Aug 4, 2023
1.26.1 Jul 31, 2023
1.0.26 Jul 31, 2023

#2023 in Hardware support


Used in 2 crates (via eusb)

MIT license

1MB
24K SLoC

C 16K SLoC // 0.3% comments Visual Studio Project 4.5K SLoC Rust 1K SLoC // 0.0% comments C++ 1K SLoC // 0.0% comments Visual Studio Solution 754 SLoC Automake 68 SLoC // 0.0% comments

Libusb Rust Bindings

The libusb-src crate provides declarations and linkage for the libusb C library.

libusb version: 1.0.26

tested on ubuntu and windows

example

use libusb_src as ffi;

fn main(){
    unsafe {
        let mut context = std::mem::MaybeUninit::<*mut ffi::libusb_context>::uninit();
        match ffi::libusb_init(context.as_mut_ptr()){
            0 => (),
            err => panic!("Failed to init libusb {}", err),
        }
        let mut list = std::mem::MaybeUninit::<*const *mut ffi::libusb_device>::uninit();
        let list_size = ffi::libusb_get_device_list(context.assume_init(), list.as_mut_ptr());
        if list_size < 0  {
            panic!("Failed to get device list {} {:p}", -list_size, list.assume_init());
        }else { 
            println!("Usb device count: {}", list_size);
        }
        ffi::libusb_free_device_list(list.assume_init(), 1);
        ffi::libusb_exit(context.assume_init());
    }
}

Cross Compile

support windows linux and android, not test ios and mac.

Dependencies

~0–2.2MB
~44K SLoC