1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
pub mod device;
pub mod event;
pub mod nv_link;
pub mod unit;

use self::device::PciInfo;
use crate::error::NvmlError;
use crate::ffi::bindings::*;
#[cfg(feature = "serde")]
use serde_derive::{Deserialize, Serialize};
use std::{convert::TryFrom, ffi::CStr};

/// Information about an excluded device.
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct ExcludedDeviceInfo {
    pci_info: PciInfo,
    uuid: String,
}

impl TryFrom<nvmlExcludedDeviceInfo_t> for ExcludedDeviceInfo {
    type Error = NvmlError;

    /**
    Construct [`ExcludedDeviceInfo`] from the corresponding C struct.

    # Errors

    * `UnexpectedVariant`, for which you can read the docs for
    */
    fn try_from(value: nvmlExcludedDeviceInfo_t) -> Result<Self, Self::Error> {
        unsafe {
            let uuid_raw = CStr::from_ptr(value.uuid.as_ptr());

            Ok(Self {
                pci_info: PciInfo::try_from(value.pciInfo, true)?,
                uuid: uuid_raw.to_str()?.into(),
            })
        }
    }
}