use crate::{pci_info::PciInfo, PciInfoError};
#[cfg(any(doc, target_os = "windows"))]
mod windows;
#[cfg(any(doc, target_os = "windows"))]
pub use windows::*;
#[cfg(any(doc, target_os = "macos"))]
mod macos;
#[cfg(any(doc, target_os = "macos"))]
pub use macos::*;
#[cfg(any(doc, target_os = "linux"))]
mod linux;
#[cfg(any(doc, target_os = "linux"))]
pub use linux::*;
#[cfg(any(doc, target_os = "freebsd"))]
mod freebsd;
#[cfg(any(doc, target_os = "freebsd"))]
pub use freebsd::*;
pub trait PciEnumerator {
fn enumerate_pci(self) -> Result<PciInfo, PciInfoError>;
}
pub fn default_pci_enumerator() -> Result<impl PciEnumerator, PciInfoError> {
#[cfg(target_os = "windows")]
return Ok(WindowsSetupApiPciEnumerator);
#[cfg(target_os = "macos")]
return Ok(MacOsIoKitPciEnumerator);
#[cfg(target_os = "freebsd")]
return Ok(FreeBsdDevPciEnumerator);
#[cfg(target_os = "linux")]
return Ok(LinuxProcFsPciEnumerator::Exhaustive);
#[cfg(not(any(
target_os = "macos",
target_os = "linux",
target_os = "windows",
target_os = "freebsd"
)))]
Err::<InvalidPciEnumerator, PciInfoError>(PciInfoError::NoDefaultPciEnumeratorForPlatform)
}
#[allow(dead_code)]
struct InvalidPciEnumerator;
impl PciEnumerator for InvalidPciEnumerator {
fn enumerate_pci(self) -> Result<PciInfo, PciInfoError> {
unreachable!()
}
}