Skip to content

Instantly share code, notes, and snippets.

@xobs
Last active November 28, 2025 00:36
Show Gist options
  • Select an option

  • Save xobs/c6ecb5e4e2b1ebb08d38215d931f897e to your computer and use it in GitHub Desktop.

Select an option

Save xobs/c6ecb5e4e2b1ebb08d38215d931f897e to your computer and use it in GitHub Desktop.
Display devices connected to a machine along with their bus listing
#!/usr/bin/env cargo
---
package.edition = "2024"
dependencies.nusb = { version = "0.2.1" }
---
use nusb::MaybeFuture;
fn main() {
let mut bt = std::collections::BTreeMap::new();
for dev in nusb::list_devices().wait().unwrap() {
let mut s = format!("{}", dev.bus_id());
for port in dev.port_chain() {
s.push_str(&format!("/{port}"));
}
let v = format!(
"{:04x}:{:04x}:{} @ {s} {} - {}",
dev.vendor_id(),
dev.product_id(),
dev.serial_number().unwrap_or("<no serial>"),
dev.manufacturer_string().unwrap_or("<no manufacturer>"),
dev.product_string().unwrap_or("<no product>")
);
if bt.contains_key(&s) {
println!("{v} appears twice!");
}
bt.insert(s, v);
}
for entry in bt.values() {
println!("{entry}");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment