1#![warn(clippy::pedantic)]
2#![warn(missing_docs)]
3#![allow(clippy::module_name_repetitions)]
4#![allow(clippy::must_use_candidate)]
5#![allow(clippy::redundant_closure_for_method_calls)]
6#![doc = include_str!("../README.md")]
7
8mod error;
9mod info;
10mod path;
11
12use cfg_if::cfg_if;
13pub use error::Error;
14pub use info::DeviceInfo;
15pub use path::DevicePath;
16
17#[cfg(unix)]
18mod linux;
19
20#[cfg(windows)]
21mod win32;
22
23pub struct Devices {
25 _marker: (),
26}
27
28impl Devices {
29 pub fn get() -> Result<Vec<DeviceInfo>, Error> {
33 let mut devices = Self::pci()?;
34 devices.extend(Self::usb()?);
35
36 Ok(devices)
37 }
38
39 pub fn pci() -> Result<Vec<DeviceInfo>, Error> {
43 cfg_if! {
44 if #[cfg(unix)] {
45 linux::get_pci()
46 } else if #[cfg(windows)] {
47 win32::get_pci()
48 } else {
49 Err(Error::UnsupportedPlatform)
50 }
51 }
52 }
53
54 pub fn usb() -> Result<Vec<DeviceInfo>, Error> {
58 cfg_if! {
59 if #[cfg(unix)] {
60 linux::get_usb()
61 } else if #[cfg(windows)] {
62 win32::get_usb()
63 } else {
64 Err(Error::UnsupportedPlatform)
65 }
66 }
67 }
68}