sinf 0.1.0

Library for obtaining in-depth system information at both the hardware and software levels
Documentation
use std::fmt;
use std::str::FromStr;

macro_rules! pid_decl {
    ($typ:ty) => {
        #[doc = "Process ID. Castable from/to integer types."]
        #[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
        #[repr(transparent)]
        pub struct Pid(pub(crate) $typ);

        impl From<usize> for Pid {
            fn from(v: usize) -> Self {
                Self(v as _)
            }
        }
        impl From<Pid> for usize {
            fn from(v: Pid) -> Self {
                v.0 as _
            }
        }
        impl FromStr for Pid {
            type Err = <$typ as FromStr>::Err;
            fn from_str(s: &str) -> Result<Self, Self::Err> {
                Ok(Self(<$typ>::from_str(s)?))
            }
        }
        impl fmt::Display for Pid {
            fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
                write!(f, "{}", self.0)
            }
        }
        impl Pid {
            /// Converts a [`Pid`][crate::Pid] into a [`u32`].
            pub fn as_u32(self) -> u32 {
                self.0 as _
            }
            /// Converts a [`u32`] into a [`Pid`][crate::Pid].
            pub fn from_u32(v: u32) -> Self {
                Self(v as _)
            }
        }
    };
}

cfg_select! {
    all(
        any(
            target_os = "freebsd",
            target_os = "netbsd",
            target_os = "linux",
            target_os = "android",
            target_os = "macos",
            target_os = "ios",
        )
    ) => {
        use libc::pid_t;

        pid_decl!(pid_t);
    }
    _ => {
        pid_decl!(usize);
    }
}