1use std::fs::read_dir;
2use std::io;
3use std::path::{Path, PathBuf};
4
5use tap::prelude::*;
6
7use super::DeviceAttribute;
8use crate::port::Port;
9
10pub fn device_nodes_by_class(class: &str) -> Vec<PathBuf> {
11 let class_path = PathBuf::from("/sys/class").tap_mut(|it| it.push(class));
12 read_dir(class_path)
13 .map(|dir_entries| {
14 dir_entries.filter_map(Result::ok).map(|it| it.path()).collect()
15 })
16 .unwrap_or_default()
17}
18
19pub fn device_node_driver_name<P: AsRef<Path>>(
20 device_node: P,
21) -> io::Result<String> {
22 String::of_device(device_node, "driver_name")
23}
24
25pub fn device_node_port<P: AsRef<Path>>(device_node: P) -> io::Result<Port> {
26 Port::of_device(device_node, "address")
27}