Crate hidapi

source ·
Expand description

This crate provides a rust abstraction over the features of the C library hidapi by signal11.


This crate is on and can be used by adding hidapi to the dependencies in your project’s Cargo.toml.


extern crate hidapi;

use hidapi::HidApi;

fn main() {
    println!("Printing all available hid devices:");

    match HidApi::new() {
        Ok(api) => {
            for device in api.device_list() {
                println!("{:04x}:{:04x}", device.vendor_id(), device.product_id());
        Err(e) => {
            eprintln!("Error: {}", e);

Feature flags

  • linux-static-libusb: uses statically linked libusb backend on Linux (default)
  • linux-static-hidraw: uses statically linked hidraw backend on Linux
  • linux-shared-libusb: uses dynamically linked libusb backend on Linux
  • linux-shared-hidraw: uses dynamically linked hidraw backend on Linux
  • illumos-static-libusb: uses statically linked libusb backend on Illumos (default)
  • illumos-shared-libusb: uses statically linked hidraw backend on Illumos
  • macos-shared-device: enables shared access to HID devices on MacOS

MacOS Shared device access

Since hidapi 0.12 it is possible to open MacOS devices with shared access, so that multiple HidDevice handles can access the same physical device. For backward compatibility this is an opt-in that can be enabled with the macos-shared-device feature flag.


Device information. Use accessors to extract information about Hid devices.
Object for handling hidapi context and implementing RAII for it. Only one instance can exist at a time.
Object for accessing HID device
Storage for device related information


Type Definitions