Skip to content

Commit

Permalink
a more applied doc list_buses example
Browse files Browse the repository at this point in the history
  • Loading branch information
tuna-f1sh committed Sep 2, 2024
1 parent a0d5066 commit 3efdb54
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ pub fn list_devices() -> Result<impl Iterator<Item = DeviceInfo>, Error> {

/// Get an iterator listing the system USB buses.
///
/// ### Example
/// ### Examples
///
/// Filter for a specific bus ID:
///
/// ```no_run
/// use nusb;
Expand All @@ -162,6 +164,20 @@ pub fn list_devices() -> Result<impl Iterator<Item = DeviceInfo>, Error> {
/// .expect("bus #1 not found");
/// ```
///
/// Group devices by bus:
///
/// ```no_run
/// use std::collections::HashMap;
///
/// let devices = nusb::list_devices().unwrap().collect::<Vec<_>>();
/// let buses: HashMap<String, (nusb::BusInfo, Vec::<nusb::DeviceInfo>)> = nusb::list_buses().unwrap()
/// .map(|bus| {
/// let bus_id = bus.bus_id().to_owned();
/// (bus.bus_id().to_owned(), (bus, devices.clone().into_iter().filter(|dev| dev.bus_id() == bus_id).collect()))
/// })
/// .collect();
/// ```
///
/// ### Platform-specific notes
/// * On Linux, the abstraction of the "bus" is a phony device known as the root hub. This device is available at bus.root_hub()
pub fn list_buses() -> Result<impl Iterator<Item = BusInfo>, Error> {
Expand Down

0 comments on commit 3efdb54

Please sign in to comment.