sinf 0.1.0

Library for obtaining in-depth system information at both the hardware and software levels
Documentation
use crate::PCI;

// `pcidebug` format: either `busNum:deviceNum:functionNum` or `busNum:deviceNum:functionNum(secBusNum:subBusNum)` (decimal).
pub(super) fn parse_pcidebug(pcidebug: &str) -> Option<PCI> {
    let (address, _) = pcidebug.split_once('(').unwrap_or((pcidebug, ""));
    let mut parts = address.split(':');
    let bus: u8 = parts.next()?.parse().ok()?;
    let device: u8 = parts.next()?.parse().ok()?;
    let function: u8 = parts.next()?.parse().ok()?;

    if device > 0x1f {
        return None;
    }
    if function > 0x07 {
        return None;
    }

    Some(PCI {
        domain: 0,
        bus: bus as u32,
        device: device as u32,
        function: function as u32,
    })
}