sinf 0.1.0

Library for obtaining in-depth system information at both the hardware and software levels
Documentation
use crate::Error;
#[cfg(all(target_os = "macos", not(feature = "apple-sandbox")))]
use crate::sys::io_platform;
use crate::sys::utils::get_sysctl_str;

pub(crate) struct ProductInner;

impl ProductInner {
    pub(crate) fn family() -> Result<String, Error> {
        get_sysctl_str(b"hw.model\0")
            .ok_or_else(|| Error::Other("failed to retrieve product family".into()))
    }

    pub(crate) fn name() -> Result<String, Error> {
        if let Ok(family) = Self::family() {
            return Ok(family);
        }

        #[cfg(all(target_os = "macos", not(feature = "apple-sandbox")))]
        {
            io_platform::product_name()
                .ok_or_else(|| Error::Other("failed to retrieve product name".into()))
        }
        #[cfg(not(all(target_os = "macos", not(feature = "apple-sandbox"))))]
        {
            Err(Error::Unsupported)
        }
    }

    pub(crate) fn serial_number() -> Result<String, Error> {
        #[cfg(all(target_os = "macos", not(feature = "apple-sandbox")))]
        {
            io_platform::serial_number()
                .ok_or_else(|| Error::Other("failed to retrieve product serial number".into()))
        }
        #[cfg(not(all(target_os = "macos", not(feature = "apple-sandbox"))))]
        {
            Err(Error::Unsupported)
        }
    }

    pub(crate) fn stock_keeping_unit() -> Result<String, Error> {
        Err(Error::Unsupported)
    }

    pub(crate) fn uuid() -> Result<String, Error> {
        #[cfg(all(target_os = "macos", not(feature = "apple-sandbox")))]
        {
            io_platform::uuid()
                .ok_or_else(|| Error::Other("failed to retrieve product uuid".into()))
        }
        #[cfg(not(all(target_os = "macos", not(feature = "apple-sandbox"))))]
        {
            Err(Error::Unsupported)
        }
    }

    pub(crate) fn version() -> Result<String, Error> {
        #[cfg(all(target_os = "macos", not(feature = "apple-sandbox")))]
        {
            io_platform::version()
                .ok_or_else(|| Error::Other("failed to retrieve product version".into()))
        }
        #[cfg(not(all(target_os = "macos", not(feature = "apple-sandbox"))))]
        {
            Err(Error::Unsupported)
        }
    }

    pub(crate) fn vendor_name() -> Result<String, Error> {
        crate::Motherboard::new()?
            .vendor_name()
            .ok_or_else(|| Error::Other("failed to retrieve vendor name".into()))
    }
}