sinf 0.1.0

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

const NAME: &[u8] = b"machdep.dmi.system-product\0";
const SERIAL_NUMBER: &[u8] = b"machdep.dmi.system-serial\0";
const UUID: &[u8] = b"machdep.dmi.system-uuid\0";
const VERSION: &[u8] = b"machdep.dmi.system-version\0";
const VENDOR: &[u8] = b"machdep.dmi.system-vendor\0";

pub(crate) struct ProductInner;

impl ProductInner {
    fn required(key: &[u8], message: &'static str) -> Result<String, Error> {
        get_sys_value_str_by_name(key).ok_or_else(|| Error::Other(message.into()))
    }

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

    pub(crate) fn name() -> Result<String, Error> {
        Self::required(NAME, "failed to retrieve product name")
    }

    pub(crate) fn serial_number() -> Result<String, Error> {
        Self::required(SERIAL_NUMBER, "failed to retrieve product serial number")
    }

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

    pub(crate) fn uuid() -> Result<String, Error> {
        Self::required(UUID, "failed to retrieve product uuid")
    }

    pub(crate) fn version() -> Result<String, Error> {
        Self::required(VERSION, "failed to retrieve product version")
    }

    pub(crate) fn vendor_name() -> Result<String, Error> {
        Self::required(VENDOR, "failed to retrieve product vendor name")
    }
}