nv_redfish/computer_system/
bios.rs1use crate::schema::redfish::bios::Bios as BiosSchema;
18use crate::Error;
19use crate::NvBmc;
20use nv_redfish_core::Bmc;
21use nv_redfish_core::EdmPrimitiveType;
22use nv_redfish_core::NavProperty;
23use std::marker::PhantomData;
24use std::sync::Arc;
25
26pub struct Bios<B: Bmc> {
30 data: Arc<BiosSchema>,
31 _marker: PhantomData<B>,
32}
33
34impl<B: Bmc> Bios<B> {
35 pub(crate) async fn new(
37 bmc: &NvBmc<B>,
38 nav: &NavProperty<BiosSchema>,
39 ) -> Result<Self, Error<B>> {
40 nav.get(bmc.as_ref())
41 .await
42 .map_err(crate::Error::Bmc)
43 .map(|data| Self {
44 data,
45 _marker: PhantomData,
46 })
47 }
48
49 #[must_use]
51 pub fn raw(&self) -> Arc<BiosSchema> {
52 self.data.clone()
53 }
54
55 #[must_use]
57 pub fn attribute<'a>(&'a self, name: &str) -> Option<BiosAttributeRef<'a>> {
58 self.data
59 .attributes
60 .as_ref()
61 .and_then(|attributes| attributes.dynamic_properties.get(name))
62 .map(|v| BiosAttributeRef::new(v.as_ref()))
63 }
64}
65
66pub struct BiosAttributeRef<'a> {
68 value: Option<&'a EdmPrimitiveType>,
69}
70
71impl<'a> BiosAttributeRef<'a> {
72 const fn new(value: Option<&'a EdmPrimitiveType>) -> Self {
73 Self { value }
74 }
75
76 #[must_use]
78 pub const fn is_null(&self) -> bool {
79 self.value.is_none()
80 }
81
82 #[must_use]
84 pub const fn str_value(&self) -> Option<&str> {
85 match self.value {
86 Some(EdmPrimitiveType::String(v)) => Some(v.as_str()),
87 _ => None,
88 }
89 }
90
91 #[must_use]
93 pub const fn bool_value(&self) -> Option<bool> {
94 match self.value {
95 Some(EdmPrimitiveType::Bool(v)) => Some(*v),
96 _ => None,
97 }
98 }
99
100 #[must_use]
102 pub const fn integer_value(&self) -> Option<i64> {
103 match self.value {
104 Some(EdmPrimitiveType::Integer(v)) => Some(*v),
105 _ => None,
106 }
107 }
108
109 #[must_use]
111 pub const fn decimal_value(&self) -> Option<f64> {
112 match self.value {
113 Some(EdmPrimitiveType::Decimal(v)) => Some(*v),
114 _ => None,
115 }
116 }
117}