-#[derive(Deserialize)]
-struct LocSetSerialized {
- starts_map: BTreeMap<NonZeroU32, EnumMap<LocKind, BigUint>>,
+#[derive(Debug, Clone)]
+struct BigUintAsHexString<'a>(Cow<'a, BigUint>);
+
+impl<'de, 'a> Deserialize<'de> for BigUintAsHexString<'a> {
+ fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
+ where
+ D: serde::Deserializer<'de>,
+ {
+ let text = String::deserialize(deserializer)?;
+ if let Some(text) = text.strip_prefix("0x") {
+ Ok(Self(Cow::Owned(
+ BigUint::from_str_radix(text, 0x10).map_err(<D::Error as de::Error>::custom)?,
+ )))
+ } else {
+ Err(<D::Error as de::Error>::custom(
+ "expected hex string to start with `0x`",
+ ))
+ }
+ }
+}
+
+impl Serialize for BigUintAsHexString<'_> {
+ fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
+ where
+ S: serde::Serializer,
+ {
+ format!("{:#x}", &*self.0).serialize(serializer)
+ }
+}
+
+#[derive(Deserialize, Serialize)]
+struct LocSetSerialized<'a> {
+ starts_map: BTreeMap<NonZeroU32, BTreeMap<LocKind, BigUintAsHexString<'a>>>,