smbioslib/structs/types/
management_device_threshold_data.rs1use crate::{SMBiosStruct, UndefinedStruct};
2use serde::{ser::SerializeStruct, Serialize, Serializer};
3use std::fmt;
4
5pub struct SMBiosManagementDeviceThresholdData<'a> {
19 parts: &'a UndefinedStruct,
20}
21
22impl<'a> SMBiosStruct<'a> for SMBiosManagementDeviceThresholdData<'a> {
23 const STRUCT_TYPE: u8 = 36u8;
24
25 fn new(parts: &'a UndefinedStruct) -> Self {
26 Self { parts }
27 }
28
29 fn parts(&self) -> &'a UndefinedStruct {
30 self.parts
31 }
32}
33
34impl<'a> SMBiosManagementDeviceThresholdData<'a> {
35 pub fn lower_threshold_non_critical(&self) -> Option<u16> {
37 self.parts.get_field_word(0x04)
38 }
39
40 pub fn upper_threshold_non_critical(&self) -> Option<u16> {
42 self.parts.get_field_word(0x06)
43 }
44
45 pub fn lower_threshold_critical(&self) -> Option<u16> {
47 self.parts.get_field_word(0x08)
48 }
49
50 pub fn upper_threshold_critical(&self) -> Option<u16> {
52 self.parts.get_field_word(0x0A)
53 }
54
55 pub fn lower_threshold_non_recoverable(&self) -> Option<u16> {
57 self.parts.get_field_word(0x0C)
58 }
59
60 pub fn upper_threshold_non_recoverable(&self) -> Option<u16> {
62 self.parts.get_field_word(0x0E)
63 }
64}
65
66impl fmt::Debug for SMBiosManagementDeviceThresholdData<'_> {
67 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
68 fmt.debug_struct(std::any::type_name::<SMBiosManagementDeviceThresholdData<'_>>())
69 .field("header", &self.parts.header)
70 .field(
71 "lower_threshold_non_critical",
72 &self.lower_threshold_non_critical(),
73 )
74 .field(
75 "upper_threshold_non_critical",
76 &self.upper_threshold_non_critical(),
77 )
78 .field("lower_threshold_critical", &self.lower_threshold_critical())
79 .field("upper_threshold_critical", &self.upper_threshold_critical())
80 .field(
81 "lower_threshold_non_recoverable",
82 &self.lower_threshold_non_recoverable(),
83 )
84 .field(
85 "upper_threshold_non_recoverable",
86 &self.upper_threshold_non_recoverable(),
87 )
88 .finish()
89 }
90}
91
92impl Serialize for SMBiosManagementDeviceThresholdData<'_> {
93 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
94 where
95 S: Serializer,
96 {
97 let mut state = serializer.serialize_struct("SMBiosManagementDeviceThresholdData", 7)?;
98 state.serialize_field("header", &self.parts.header)?;
99 state.serialize_field(
100 "lower_threshold_non_critical",
101 &self.lower_threshold_non_critical(),
102 )?;
103 state.serialize_field(
104 "upper_threshold_non_critical",
105 &self.upper_threshold_non_critical(),
106 )?;
107 state.serialize_field("lower_threshold_critical", &self.lower_threshold_critical())?;
108 state.serialize_field("upper_threshold_critical", &self.upper_threshold_critical())?;
109 state.serialize_field(
110 "lower_threshold_non_recoverable",
111 &self.lower_threshold_non_recoverable(),
112 )?;
113 state.serialize_field(
114 "upper_threshold_non_recoverable",
115 &self.upper_threshold_non_recoverable(),
116 )?;
117 state.end()
118 }
119}
120
121#[cfg(test)]
122mod tests {
123 use super::*;
124
125 #[test]
126 fn unit_test() {
127 let struct_type36 = vec![
128 0x24, 0x10, 0x28, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, 0x00, 0x05, 0x00,
129 0x06, 0x00, 0x00, 0x00,
130 ];
131
132 let parts = UndefinedStruct::new(&struct_type36);
133 let test_struct = SMBiosManagementDeviceThresholdData::new(&parts);
134
135 assert_eq!(test_struct.lower_threshold_non_critical(), Some(1));
136 assert_eq!(test_struct.upper_threshold_non_critical(), Some(2));
137 assert_eq!(test_struct.lower_threshold_critical(), Some(3));
138 assert_eq!(test_struct.upper_threshold_critical(), Some(4));
139 assert_eq!(test_struct.lower_threshold_non_recoverable(), Some(5));
140 assert_eq!(test_struct.upper_threshold_non_recoverable(), Some(6));
141 }
142}