libusb-src

Crates.iolibusb-src
lib.rslibusb-src
version1.27.0+1.0.26
sourcesrc
created_at2023-07-31 04:04:25.122488
updated_at2023-10-09 03:08:26.170222
descriptionFFI bindings for libusb. Can be easily cross compiled.
homepagehttps://github.com/ZR233/eusb
repositoryhttps://github.com/ZR233/eusb.git
max_upload_size
id930480
size1,524,945
周睿 (ZR233)

documentation

README

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.

Commit count: 66

cargo fmt