From 6ef01ec2e22477a222f9ee4f602f9cb06f95db43 Mon Sep 17 00:00:00 2001 From: Mingun Date: Fri, 13 Oct 2023 23:08:17 +0500 Subject: [PATCH] Change deserialization of enums 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 --- src/de/map.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/de/map.rs b/src/de/map.rs index 7abd45df..97e632da 100644 --- a/src/de/map.rs +++ b/src/de/map.rs @@ -613,7 +613,27 @@ where where V: Visitor<'de>, { - visitor.visit_enum(self) + if self.fixed_name { + match self.map.de.next()? { + // Handles UnitEnumVariant + DeEvent::Start(_) => { + // skip , read text after it and ensure that it is ended by + let text = self.map.de.read_text()?; + if text.is_empty() { + // Map empty text () 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(self, visitor: V) -> Result