1use serde::Serialize;
5use std::iter::FromIterator;
6
7use crate::core::UndefinedStruct;
8
9use super::*;
10
11#[derive(Serialize, Debug)]
16pub enum DefinedStruct<'a> {
17 Information(SMBiosInformation<'a>),
19 SystemInformation(SMBiosSystemInformation<'a>),
21 BaseBoardInformation(SMBiosBaseboardInformation<'a>),
23 SystemChassisInformation(SMBiosSystemChassisInformation<'a>),
25 ProcessorInformation(SMBiosProcessorInformation<'a>),
27 MemoryControllerInformation(SMBiosMemoryControllerInformation<'a>),
29 MemoryModuleInformation(SMBiosMemoryModuleInformation<'a>),
31 CacheInformation(SMBiosCacheInformation<'a>),
33 PortConnectorInformation(SMBiosPortConnectorInformation<'a>),
35 SystemSlot(SMBiosSystemSlot<'a>),
37 OnBoardDeviceInformation(SMBiosOnBoardDeviceInformation<'a>),
39 OemStrings(SMBiosOemStrings<'a>),
41 SystemConfigurationOptions(SMBiosSystemConfigurationOptions<'a>),
43 LanguageInformation(SMBiosBiosLanguageInformation<'a>),
45 GroupAssociations(SMBiosGroupAssociations<'a>),
47 EventLog(SMBiosSystemEventLog<'a>),
49 PhysicalMemoryArray(SMBiosPhysicalMemoryArray<'a>),
51 MemoryDevice(SMBiosMemoryDevice<'a>),
53 MemoryErrorInformation32Bit(SMBiosMemoryErrorInformation32<'a>),
55 MemoryArrayMappedAddress(SMBiosMemoryArrayMappedAddress<'a>),
57 MemoryDeviceMappedAddress(SMBiosMemoryDeviceMappedAddress<'a>),
59 BuiltInPointingDevice(SMBiosBuiltInPointingDevice<'a>),
61 PortableBattery(SMBiosPortableBattery<'a>),
63 SystemReset(SMBiosSystemReset<'a>),
65 HardwareSecurity(SMBiosHardwareSecurity<'a>),
67 SystemPowerControls(SMBiosSystemPowerControls<'a>),
69 VoltageProbe(SMBiosVoltageProbe<'a>),
71 CoolingDevice(SMBiosCoolingDevice<'a>),
73 TemperatureProbe(SMBiosTemperatureProbe<'a>),
75 ElectricalCurrentProbe(SMBiosElectricalCurrentProbe<'a>),
77 OutOfBandRemoteAccess(SMBiosOutOfBandRemoteAccess<'a>),
79 BisEntryPoint(SMBiosBisEntryPoint<'a>),
81 SystemBootInformation(SMBiosSystemBootInformation<'a>),
83 MemoryErrorInformation64Bit(SMBiosMemoryErrorInformation64<'a>),
85 ManagementDevice(SMBiosManagementDevice<'a>),
87 ManagementDeviceComponent(SMBiosManagementDeviceComponent<'a>),
89 ManagementDeviceThresholdData(SMBiosManagementDeviceThresholdData<'a>),
91 MemoryChannel(SMBiosMemoryChannel<'a>),
93 IpmiDeviceInformation(SMBiosIpmiDeviceInformation<'a>),
95 SystemPowerSupply(SMBiosSystemPowerSupply<'a>),
97 AdditionalInformation(SMBiosAdditionalInformation<'a>),
99 OnboardDevicesExtendedInformation(SMBiosOnboardDevicesExtendedInformation<'a>),
101 ManagementControllerHostInterface(SMBiosManagementControllerHostInterface<'a>),
103 TpmDevice(SMBiosTpmDevice<'a>),
105 ProcessorAdditionalInformation(SMBiosProcessorAdditionalInformation<'a>),
107 FirmwareInventoryInformation(SMBiosFirmwareInventoryInformation<'a>),
109 StringProperty(SMBiosStringProperty<'a>),
111 Inactive(SMBiosInactive<'a>),
113 EndOfTable(SMBiosEndOfTable<'a>),
115 Undefined(SMBiosUnknown<'a>),
121}
122
123impl<'a> From<&'a UndefinedStruct> for DefinedStruct<'a> {
124 fn from(undefined_struct: &'a UndefinedStruct) -> Self {
125 match undefined_struct.header.struct_type() {
126 SMBiosInformation::STRUCT_TYPE => {
127 DefinedStruct::Information(SMBiosInformation::new(undefined_struct))
128 }
129 SMBiosSystemInformation::STRUCT_TYPE => {
130 DefinedStruct::SystemInformation(SMBiosSystemInformation::new(undefined_struct))
131 }
132 SMBiosBaseboardInformation::STRUCT_TYPE => DefinedStruct::BaseBoardInformation(
133 SMBiosBaseboardInformation::new(undefined_struct),
134 ),
135 SMBiosSystemChassisInformation::STRUCT_TYPE => DefinedStruct::SystemChassisInformation(
136 SMBiosSystemChassisInformation::new(undefined_struct),
137 ),
138 SMBiosProcessorInformation::STRUCT_TYPE => DefinedStruct::ProcessorInformation(
139 SMBiosProcessorInformation::new(undefined_struct),
140 ),
141 SMBiosMemoryControllerInformation::STRUCT_TYPE => {
142 DefinedStruct::MemoryControllerInformation(SMBiosMemoryControllerInformation::new(
143 undefined_struct,
144 ))
145 }
146 SMBiosMemoryModuleInformation::STRUCT_TYPE => DefinedStruct::MemoryModuleInformation(
147 SMBiosMemoryModuleInformation::new(undefined_struct),
148 ),
149 SMBiosCacheInformation::STRUCT_TYPE => {
150 DefinedStruct::CacheInformation(SMBiosCacheInformation::new(undefined_struct))
151 }
152 SMBiosPortConnectorInformation::STRUCT_TYPE => DefinedStruct::PortConnectorInformation(
153 SMBiosPortConnectorInformation::new(undefined_struct),
154 ),
155 SMBiosSystemSlot::STRUCT_TYPE => {
156 DefinedStruct::SystemSlot(SMBiosSystemSlot::new(undefined_struct))
157 }
158 SMBiosOnBoardDeviceInformation::STRUCT_TYPE => DefinedStruct::OnBoardDeviceInformation(
159 SMBiosOnBoardDeviceInformation::new(undefined_struct),
160 ),
161 SMBiosOemStrings::STRUCT_TYPE => {
162 DefinedStruct::OemStrings(SMBiosOemStrings::new(undefined_struct))
163 }
164 SMBiosSystemConfigurationOptions::STRUCT_TYPE => {
165 DefinedStruct::SystemConfigurationOptions(SMBiosSystemConfigurationOptions::new(
166 undefined_struct,
167 ))
168 }
169 SMBiosBiosLanguageInformation::STRUCT_TYPE => DefinedStruct::LanguageInformation(
170 SMBiosBiosLanguageInformation::new(undefined_struct),
171 ),
172 SMBiosGroupAssociations::STRUCT_TYPE => {
173 DefinedStruct::GroupAssociations(SMBiosGroupAssociations::new(undefined_struct))
174 }
175 SMBiosSystemEventLog::STRUCT_TYPE => {
176 DefinedStruct::EventLog(SMBiosSystemEventLog::new(undefined_struct))
177 }
178 SMBiosPhysicalMemoryArray::STRUCT_TYPE => {
179 DefinedStruct::PhysicalMemoryArray(SMBiosPhysicalMemoryArray::new(undefined_struct))
180 }
181 SMBiosMemoryDevice::STRUCT_TYPE => {
182 DefinedStruct::MemoryDevice(SMBiosMemoryDevice::new(undefined_struct))
183 }
184 SMBiosMemoryErrorInformation32::STRUCT_TYPE => {
185 DefinedStruct::MemoryErrorInformation32Bit(SMBiosMemoryErrorInformation32::new(
186 undefined_struct,
187 ))
188 }
189 SMBiosMemoryArrayMappedAddress::STRUCT_TYPE => DefinedStruct::MemoryArrayMappedAddress(
190 SMBiosMemoryArrayMappedAddress::new(undefined_struct),
191 ),
192 SMBiosMemoryDeviceMappedAddress::STRUCT_TYPE => {
193 DefinedStruct::MemoryDeviceMappedAddress(SMBiosMemoryDeviceMappedAddress::new(
194 undefined_struct,
195 ))
196 }
197 SMBiosBuiltInPointingDevice::STRUCT_TYPE => DefinedStruct::BuiltInPointingDevice(
198 SMBiosBuiltInPointingDevice::new(undefined_struct),
199 ),
200 SMBiosPortableBattery::STRUCT_TYPE => {
201 DefinedStruct::PortableBattery(SMBiosPortableBattery::new(undefined_struct))
202 }
203 SMBiosSystemReset::STRUCT_TYPE => {
204 DefinedStruct::SystemReset(SMBiosSystemReset::new(undefined_struct))
205 }
206 SMBiosHardwareSecurity::STRUCT_TYPE => {
207 DefinedStruct::HardwareSecurity(SMBiosHardwareSecurity::new(undefined_struct))
208 }
209 SMBiosSystemPowerControls::STRUCT_TYPE => {
210 DefinedStruct::SystemPowerControls(SMBiosSystemPowerControls::new(undefined_struct))
211 }
212 SMBiosVoltageProbe::STRUCT_TYPE => {
213 DefinedStruct::VoltageProbe(SMBiosVoltageProbe::new(undefined_struct))
214 }
215 SMBiosCoolingDevice::STRUCT_TYPE => {
216 DefinedStruct::CoolingDevice(SMBiosCoolingDevice::new(undefined_struct))
217 }
218 SMBiosTemperatureProbe::STRUCT_TYPE => {
219 DefinedStruct::TemperatureProbe(SMBiosTemperatureProbe::new(undefined_struct))
220 }
221 SMBiosElectricalCurrentProbe::STRUCT_TYPE => DefinedStruct::ElectricalCurrentProbe(
222 SMBiosElectricalCurrentProbe::new(undefined_struct),
223 ),
224 SMBiosOutOfBandRemoteAccess::STRUCT_TYPE => DefinedStruct::OutOfBandRemoteAccess(
225 SMBiosOutOfBandRemoteAccess::new(undefined_struct),
226 ),
227 SMBiosBisEntryPoint::STRUCT_TYPE => {
228 DefinedStruct::BisEntryPoint(SMBiosBisEntryPoint::new(undefined_struct))
229 }
230 SMBiosSystemBootInformation::STRUCT_TYPE => DefinedStruct::SystemBootInformation(
231 SMBiosSystemBootInformation::new(undefined_struct),
232 ),
233 SMBiosMemoryErrorInformation64::STRUCT_TYPE => {
234 DefinedStruct::MemoryErrorInformation64Bit(SMBiosMemoryErrorInformation64::new(
235 undefined_struct,
236 ))
237 }
238 SMBiosManagementDevice::STRUCT_TYPE => {
239 DefinedStruct::ManagementDevice(SMBiosManagementDevice::new(undefined_struct))
240 }
241 SMBiosManagementDeviceComponent::STRUCT_TYPE => {
242 DefinedStruct::ManagementDeviceComponent(SMBiosManagementDeviceComponent::new(
243 undefined_struct,
244 ))
245 }
246 SMBiosManagementDeviceThresholdData::STRUCT_TYPE => {
247 DefinedStruct::ManagementDeviceThresholdData(
248 SMBiosManagementDeviceThresholdData::new(undefined_struct),
249 )
250 }
251 SMBiosMemoryChannel::STRUCT_TYPE => {
252 DefinedStruct::MemoryChannel(SMBiosMemoryChannel::new(undefined_struct))
253 }
254 SMBiosIpmiDeviceInformation::STRUCT_TYPE => DefinedStruct::IpmiDeviceInformation(
255 SMBiosIpmiDeviceInformation::new(undefined_struct),
256 ),
257 SMBiosSystemPowerSupply::STRUCT_TYPE => {
258 DefinedStruct::SystemPowerSupply(SMBiosSystemPowerSupply::new(undefined_struct))
259 }
260 SMBiosAdditionalInformation::STRUCT_TYPE => DefinedStruct::AdditionalInformation(
261 SMBiosAdditionalInformation::new(undefined_struct),
262 ),
263 SMBiosOnboardDevicesExtendedInformation::STRUCT_TYPE => {
264 DefinedStruct::OnboardDevicesExtendedInformation(
265 SMBiosOnboardDevicesExtendedInformation::new(undefined_struct),
266 )
267 }
268 SMBiosManagementControllerHostInterface::STRUCT_TYPE => {
269 DefinedStruct::ManagementControllerHostInterface(
270 SMBiosManagementControllerHostInterface::new(undefined_struct),
271 )
272 }
273 SMBiosTpmDevice::STRUCT_TYPE => {
274 DefinedStruct::TpmDevice(SMBiosTpmDevice::new(undefined_struct))
275 }
276 SMBiosProcessorAdditionalInformation::STRUCT_TYPE => {
277 DefinedStruct::ProcessorAdditionalInformation(
278 SMBiosProcessorAdditionalInformation::new(undefined_struct),
279 )
280 }
281 SMBiosFirmwareInventoryInformation::STRUCT_TYPE => {
282 DefinedStruct::FirmwareInventoryInformation(
283 SMBiosFirmwareInventoryInformation::new(undefined_struct),
284 )
285 }
286 SMBiosStringProperty::STRUCT_TYPE => {
287 DefinedStruct::StringProperty(SMBiosStringProperty::new(undefined_struct))
288 }
289 SMBiosInactive::STRUCT_TYPE => {
290 DefinedStruct::Inactive(SMBiosInactive::new(undefined_struct))
291 }
292 SMBiosEndOfTable::STRUCT_TYPE => {
293 DefinedStruct::EndOfTable(SMBiosEndOfTable::new(undefined_struct))
294 }
295 _ => DefinedStruct::Undefined(SMBiosUnknown::new(undefined_struct)),
296 }
297 }
298}
299
300#[derive(Serialize, Debug)]
304pub struct DefinedStructTable<'a>(Vec<DefinedStruct<'a>>);
305
306impl<'a> DefinedStructTable<'a> {
307 fn new() -> DefinedStructTable<'a> {
308 DefinedStructTable(Vec::new())
309 }
310
311 fn add(&mut self, elem: DefinedStruct<'a>) {
312 self.0.push(elem);
313 }
314}
315
316impl<'a> IntoIterator for DefinedStructTable<'a> {
317 type Item = DefinedStruct<'a>;
318 type IntoIter = std::vec::IntoIter<Self::Item>;
319
320 fn into_iter(self) -> Self::IntoIter {
321 self.0.into_iter()
322 }
323}
324
325impl<'a> FromIterator<&'a UndefinedStruct> for DefinedStructTable<'a> {
326 fn from_iter<I: IntoIterator<Item = &'a UndefinedStruct>>(iter: I) -> Self {
327 let mut defined_struct_table = DefinedStructTable::new();
328
329 for undefined_struct in iter {
330 defined_struct_table.add(undefined_struct.into());
331 }
332
333 defined_struct_table
334 }
335}