use crate::bitmasks::nv_link::PacketTypes;
use crate::enum_wrappers::nv_link::UtilizationCountUnit;
use crate::error::NvmlError;
use crate::ffi::bindings::*;
#[cfg(feature = "serde")]
use serde_derive::{Deserialize, Serialize};
use std::convert::TryFrom;
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct UtilizationControl {
pub units: UtilizationCountUnit,
pub packet_filter: PacketTypes,
}
impl UtilizationControl {
pub fn as_c(&self) -> nvmlNvLinkUtilizationControl_t {
nvmlNvLinkUtilizationControl_t {
units: self.units.as_c(),
pktfilter: self.packet_filter.bits(),
}
}
}
impl TryFrom<nvmlNvLinkUtilizationControl_t> for UtilizationControl {
type Error = NvmlError;
fn try_from(value: nvmlNvLinkUtilizationControl_t) -> Result<Self, Self::Error> {
let bits = value.pktfilter;
Ok(UtilizationControl {
units: UtilizationCountUnit::try_from(value.units)?,
packet_filter: PacketTypes::from_bits_truncate(bits),
})
}
}