Skip to content

Commit 42905be

Browse files
committed
SerdePspEntrySourceValue: Support "Unknown" variant.
1 parent c469e38 commit 42905be

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

ahib-config/src/lib.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ impl TryFromSerdeDirectoryEntryWithContext<SerdePspDirectoryEntry>
115115
#[non_exhaustive]
116116
pub enum SerdePspEntrySourceValue {
117117
PspSoftFuseChain(PspSoftFuseChain),
118+
Unknown(u64),
118119
}
119120

120121
impl SerdePspEntrySourceValue {
@@ -123,21 +124,25 @@ impl SerdePspEntrySourceValue {
123124
PspDirectoryEntryType::PspSoftFuseChain => {
124125
Ok(Self::PspSoftFuseChain(PspSoftFuseChain::from(value)))
125126
}
126-
_ => Err(Error::PspEntrySourceUnknown(typ)),
127+
_ => Ok(SerdePspEntrySourceValue::Unknown(value)),
127128
}
128129
}
129130

130131
pub fn to_u64(
131132
&self,
132133
typ_or_err: std::result::Result<PspDirectoryEntryType, amd_efs::Error>,
133134
) -> Result<u64> {
134-
let typ = typ_or_err.unwrap();
135-
match typ {
136-
PspDirectoryEntryType::PspSoftFuseChain => match self {
137-
Self::PspSoftFuseChain(x) => Ok(u64::from(*x)),
135+
if let SerdePspEntrySourceValue::Unknown(x) = self {
136+
Ok(*x)
137+
} else {
138+
let typ = typ_or_err.unwrap();
139+
match typ {
140+
PspDirectoryEntryType::PspSoftFuseChain => match self {
141+
Self::PspSoftFuseChain(x) => Ok(u64::from(*x)),
142+
_ => Err(Error::PspEntrySourceUnknown(typ)),
143+
},
138144
_ => Err(Error::PspEntrySourceUnknown(typ)),
139-
},
140-
_ => Err(Error::PspEntrySourceUnknown(typ)),
145+
}
141146
}
142147
}
143148
}
@@ -146,15 +151,14 @@ impl<'de> serde::Deserialize<'de> for SerdePspEntrySourceValue {
146151
fn deserialize<D: serde::Deserializer<'de>>(
147152
deserializer: D,
148153
) -> std::result::Result<Self, D::Error> {
149-
// rest delegate to PspSoftFuseChain, if that makes sense.
150154
struct ModeVisitor;
151155
impl<'de> serde::de::Visitor<'de> for ModeVisitor {
152156
type Value = SerdePspEntrySourceValue;
153157
fn expecting(
154158
&self,
155159
formatter: &mut core::fmt::Formatter<'_>,
156160
) -> core::fmt::Result {
157-
formatter.write_str("'Disabled', 'Enabled', 0 or 1")
161+
formatter.write_str("dict")
158162
}
159163
fn visit_map<A>(
160164
self,
@@ -169,7 +173,6 @@ impl<'de> serde::Deserialize<'de> for SerdePspEntrySourceValue {
169173
)?;
170174
Ok(SerdePspEntrySourceValue::PspSoftFuseChain(chain))
171175
}
172-
173176
fn visit_i64<E: serde::de::Error>(
174177
self,
175178
value: i64,

0 commit comments

Comments
 (0)