sinf 0.1.0

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

/// Information about a GPU.
#[doc = include_str!("../../docs/snippets/gpu.md")]
pub struct Gpus {
    pub(crate) inner: GpusInner,
}

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

    impl_new_with_refreshed_list!(Gpus, false);

    /// Refreshes the GPU list.
    pub fn refresh(&mut self, remove_not_listed_gpus: bool) {
        self.inner.refresh();
        if remove_not_listed_gpus {
            self.inner.gpus.retain_mut(|c| {
                if !c.inner.updated {
                    return false;
                }
                c.inner.updated = false;
                true
            });
        } else {
            for gpu in &mut self.inner.gpus {
                gpu.inner.updated = false;
            }
        }
    }
}

impl_collection_field!(Gpus, Gpu, inner.gpus);

impl From<Gpus> for Vec<Gpu> {
    fn from(mut gpus: Gpus) -> Self {
        // Required because `Gpus` implements `Drop` on Windows.
        std::mem::take(&mut gpus.inner.gpus)
    }
}