use hidapi::HidApi; pub fn search(api: &HidApi, vendor_name: String) -> anyhow::Result<()> { for device in api.device_list() { if let Some(string) = device.manufacturer_string() { if string.to_lowercase().contains(&vendor_name.to_lowercase()) { println!( "Device matches: {} (VID) - {} (PID) {}:{} - at {} by {} via {:#?}", device.vendor_id(), device.product_id(), device.usage_page(), device.usage(), device.path().to_str()?, string, device.bus_type(), ); println!( " {} (Interface {}):", match device.product_string() { Some(s) => s, _ => "", }, device.interface_number() ); let mut descriptor = vec![0u8; 2048]; match device .open_device(api) .and_then(|dev| dev.get_report_descriptor(&mut descriptor)) { Ok(length) => { println!(" {} (descriptor)", { &descriptor[..length] .iter() .map(|val| val.to_string()) .collect::() }) } Err(err) => println!(" Failed to retrieve descriptor ({:?})", err), } println!(); } } else { eprintln!( "Device without manufacturer string ({})", device.product_id() ); } } Ok(()) }