File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -153,7 +153,9 @@ pub fn list_devices() -> Result<impl Iterator<Item = DeviceInfo>, Error> {
153
153
154
154
/// Get an iterator listing the system USB buses.
155
155
///
156
- /// ### Example
156
+ /// ### Examples
157
+ ///
158
+ /// Filter for a specific bus ID:
157
159
///
158
160
/// ```no_run
159
161
/// use nusb;
@@ -162,6 +164,20 @@ pub fn list_devices() -> Result<impl Iterator<Item = DeviceInfo>, Error> {
162
164
/// .expect("bus #1 not found");
163
165
/// ```
164
166
///
167
+ /// Group devices by bus:
168
+ ///
169
+ /// ```no_run
170
+ /// use std::collections::HashMap;
171
+ ///
172
+ /// let devices = nusb::list_devices().unwrap().collect::<Vec<_>>();
173
+ /// let buses: HashMap<String, (nusb::BusInfo, Vec::<nusb::DeviceInfo>)> = nusb::list_buses().unwrap()
174
+ /// .map(|bus| {
175
+ /// let bus_id = bus.bus_id().to_owned();
176
+ /// (bus.bus_id().to_owned(), (bus, devices.clone().into_iter().filter(|dev| dev.bus_id() == bus_id).collect()))
177
+ /// })
178
+ /// .collect();
179
+ /// ```
180
+ ///
165
181
/// ### Platform-specific notes
166
182
/// * On Linux, the abstraction of the "bus" is a phony device known as the root hub. This device is available at bus.root_hub()
167
183
pub fn list_buses ( ) -> Result < impl Iterator < Item = BusInfo > , Error > {
You can’t perform that action at this time.
0 commit comments