# hid-descriptor crate
This is a utility for generating a binary USB HID report descriptor from Rust code.
It can be used from `build.rs` so that the descriptor is generated at compile time,
and the descriptor bytes can be included in the code, with no runtime cost.
### Example
```toml
[build-dependencies]
hid-descriptor = "0.1.0"
```
```rust
// `build.rs`
use std::path::PathBuf;
use hid_descriptor::*;
use hid_types::hid::{IoFlags, KnownCollectionType};
use hid_types::id::usage::{KnownUsagePage, generic_desktop, keyboard_keypad};
fn main() {
println!("cargo:rerun-if-changed=build.rs");
let out_dir = PathBuf::from(std::env::var_os("OUT_DIR").unwrap());
let descriptor_path = out_dir.join("descriptor.bin");
println!("cargo:rerun-if-changed={}", descriptor_path.display());
let bytes = [
usage_page(KnownUsagePage::GenericDesktop),
usage(generic_desktop::KnownUsage::Gamepad),
collection(KnownCollectionType::Application),
usage_page(KnownUsagePage::Button),
usage_minimum(1u16),
usage_maximum(8u16),
logical_minimum(0),
logical_maximum(1),
report_size(1),
report_count(8),
input(IoFlags::data().variable()),
end_collection(),
];
write_to_file(bytes, descriptor_path).unwrap();
}
```
```rust
// In your crate, compile in the descriptor bytes.
static GAMEPAD_DESCRIPTOR: &[u8] =
include_bytes!(concat!(env!("OUT_DIR"), "/descriptor.bin"));
```