sinf 0.1.0

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

use crate::support::impl_get_set::impl_get_set;

/// The supported kinds of disks.
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
pub enum DiskKind {
    /// An HDD.
    HDD,
    /// An SSD.
    SSD,
    /// An external disk, such as USB or SD.
    External,
    /// A network disk.
    Network,
    /// A virtual disk image, such as an ISO or an Apple Disk Image (.dmg).
    DiskImage,
    /// An unknown disk type.
    Unknown(isize),
}

impl fmt::Display for DiskKind {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.write_str(match *self {
            DiskKind::HDD => "HDD",
            DiskKind::SSD => "SSD",
            DiskKind::External => "External",
            DiskKind::Network => "Network",
            DiskKind::DiskImage => "Disk Image",
            _ => "Unknown",
        })
    }
}

/// Selects which [`Disk`][crate::disk::Disk] fields to refresh.
#[derive(Clone, Copy, Debug)]
pub struct DiskRefreshKind {
    kind: bool,
    storage: bool,
    io_usage: bool,
    network: bool,
}

impl Default for DiskRefreshKind {
    /// Creates a `DiskRefreshKind` with these defaults: - `kind`: `true`
    fn default() -> Self {
        Self {
            kind: true,
            storage: true,
            io_usage: true,
            network: false,
        }
    }
}

impl DiskRefreshKind {
    /// Creates a `DiskRefreshKind` with every option disabled.
    pub fn nothing() -> Self {
        Self {
            kind: false,
            storage: false,
            io_usage: false,
            network: false,
        }
    }

    /// Creates a `DiskRefreshKind` with every option enabled.
    pub fn everything() -> Self {
        Self {
            kind: true,
            storage: true,
            io_usage: true,
            network: true,
        }
    }

    impl_get_set!(DiskRefreshKind, kind, with_kind, without_kind);
    impl_get_set!(DiskRefreshKind, storage, with_storage, without_storage);
    impl_get_set!(DiskRefreshKind, io_usage, with_io_usage, without_io_usage);
    impl_get_set!(DiskRefreshKind, network, with_network, without_network);
}