Treat unmatched non-exhaustive remote variant as serde(skip)

This commit is contained in:
David Tolnay
2023-08-13 21:14:33 -07:00
parent cb490ec16d
commit 8d3a03288b
4 changed files with 30 additions and 1 deletions
+13
View File
@@ -1370,3 +1370,16 @@ impl Serialize for AdjacentlyTaggedEnumVariant {
serializer.serialize_unit_variant(self.enum_name, self.variant_index, self.variant_name)
}
}
// Error when Serialize for a non_exhaustive remote enum encounters a variant
// that is not recognized.
pub struct CannotSerializeVariant<T>(pub T);
impl<T> Display for CannotSerializeVariant<T>
where
T: Debug,
{
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
write!(formatter, "enum variant cannot be serialized: {:?}", self.0)
}
}