Crates.io | libusb-src |
lib.rs | libusb-src |
version | 1.27.0+1.0.26 |
source | src |
created_at | 2023-07-31 04:04:25.122488 |
updated_at | 2023-10-09 03:08:26.170222 |
description | FFI bindings for libusb. Can be easily cross compiled. |
homepage | https://github.com/ZR233/eusb |
repository | https://github.com/ZR233/eusb.git |
max_upload_size | |
id | 930480 |
size | 1,524,945 |
The libusb-src
crate provides declarations and linkage for the libusb
C library.
libusb version: 1.0.26
tested on ubuntu and windows
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());
}
}
support windows linux and android, not test ios and mac.