nvml_wrapper/enums/
unit.rs

1use crate::error::NvmlError;
2use crate::ffi::bindings::*;
3#[cfg(feature = "serde")]
4use serde_derive::{Deserialize, Serialize};
5use std::{convert::TryFrom, ffi::CStr};
6
7/// LED states for an S-class unit.
8#[derive(Debug, Clone, Eq, PartialEq, Hash)]
9#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10pub enum LedState {
11    /// Indicates good health.
12    Green,
13    /// Indicates a problem along with the accompanying cause.
14    Amber(String),
15}
16
17impl TryFrom<nvmlLedState_t> for LedState {
18    type Error = NvmlError;
19
20    /**
21    Construct `LedState` from the corresponding C struct.
22
23    # Errors
24
25    * `UnexpectedVariant`, for which you can read the docs for
26    */
27    fn try_from(value: nvmlLedState_t) -> Result<Self, Self::Error> {
28        let color = value.color;
29
30        match color {
31            nvmlLedColor_enum_NVML_LED_COLOR_GREEN => Ok(LedState::Green),
32            nvmlLedColor_enum_NVML_LED_COLOR_AMBER => unsafe {
33                let cause_raw = CStr::from_ptr(value.cause.as_ptr());
34                Ok(LedState::Amber(cause_raw.to_str()?.into()))
35            },
36            _ => Err(NvmlError::UnexpectedVariant(color)),
37        }
38    }
39}
40
41/// The type of temperature reading to take for a `Unit`.
42///
43/// Available readings depend on the product.
44#[repr(u32)]
45#[derive(Debug, Clone, Eq, PartialEq, Hash)]
46#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
47pub enum TemperatureReading {
48    Intake = 0,
49    Exhaust = 1,
50    Board = 2,
51}