-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathwalk_sp_data.rs
30 lines (26 loc) · 886 Bytes
/
walk_sp_data.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use cyme::profiler::{self, Device};
fn recursive_map_devices(device: &Device) {
// the alternate format will print with colour
println!("Device: {:#}", device);
if let Some(v) = device.devices.as_ref() {
for d in v {
recursive_map_devices(d)
}
};
}
fn main() -> Result<(), String> {
// get all system devices
let sp_usb = profiler::get_spusb()
.map_err(|e| format!("Failed to gather system USB data from libusb, Error({})", e))?;
// SPUSBDataType contains buses...
for bus in sp_usb.buses {
// which may contain devices...
if let Some(devices) = bus.devices {
// to walk all the devices, since each device can have devices attached, call a recursive function
for device in devices {
recursive_map_devices(&device);
}
}
}
Ok(())
}