sinf 0.1.0

Library for obtaining in-depth system information at both the hardware and software levels
Documentation
use crate::{Disk, DiskRefreshKind, Error};

/// A collection of disks.
#[doc = include_str!("../../docs/snippets/disk.md")]
pub struct Disks {
    inner: crate::DisksInner,
}

impl_collection_method!(Disks, Disk, inner, list, list_mut);

impl Disks {
    /// Creates an empty [`Disks`].
    pub fn new() -> Result<Self, Error> {
        Ok(Self {
            inner: crate::DisksInner::new()?,
        })
    }

    /// Creates a [`Disks`] with the disk list loaded.
    pub fn new_with_refreshed_list() -> Result<Self, Error> {
        Self::new_with_refreshed_list_specifics(DiskRefreshKind::default())
    }

    /// Creates a [`Disks`] with the disk list loaded and refreshed according to the given [`DiskRefreshKind`].
    pub fn new_with_refreshed_list_specifics(refreshes: DiskRefreshKind) -> Result<Self, Error> {
        let mut disks = Self::new()?;
        disks.refresh_specifics(false, refreshes);
        Ok(disks)
    }

    /// Refreshes the information of the listed disks.
    pub fn refresh(&mut self, remove_not_listed_disks: bool) {
        self.inner
            .refresh_specifics(remove_not_listed_disks, DiskRefreshKind::everything());
    }

    /// Refreshes disk information according to the given [`DiskRefreshKind`].
    pub fn refresh_specifics(&mut self, remove_not_listed_disks: bool, refreshes: DiskRefreshKind) {
        self.inner
            .refresh_specifics(remove_not_listed_disks, refreshes);
    }
}

impl From<Disks> for Vec<Disk> {
    fn from(disks: Disks) -> Self {
        disks.inner.into_vec()
    }
}