Skip to content

Commit

Permalink
Change deserialization of enums
Browse files Browse the repository at this point in the history
failures (1):
    without_root::enum_::externally_tagged::text_variant::text_field::unit

Fixed (5):
    without_root::enum_::externally_tagged::normal_field2::unit
    without_root::enum_::externally_tagged::normal_field::unit
    without_root::enum_::externally_tagged::text_variant::normal_field::unit
  • Loading branch information
Mingun committed Oct 17, 2023
1 parent 11fa348 commit 6ef01ec
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/de/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,27 @@ where
where
V: Visitor<'de>,
{
visitor.visit_enum(self)
if self.fixed_name {
match self.map.de.next()? {
// Handles <field>UnitEnumVariant</field>
DeEvent::Start(_) => {
// skip <field>, read text after it and ensure that it is ended by </field>
let text = self.map.de.read_text()?;
if text.is_empty() {
// Map empty text (<field/>) to a special `$text` variant
visitor.visit_enum(SimpleTypeDeserializer::from_text(TEXT_KEY.into()))
} else {
visitor.visit_enum(SimpleTypeDeserializer::from_text(text))
}
}
// SAFETY: we use that deserializer with `fixed_name == true`
// only from the `MapAccess::next_value_seed` and only when we
// peeked `Start` event
_ => unreachable!(),
}
} else {
visitor.visit_enum(self)
}
}

fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
Expand Down

0 comments on commit 6ef01ec

Please sign in to comment.