From 129212d9198c119d11bce486902510ee49487875 Mon Sep 17 00:00:00 2001 From: Roland Fredenhagen Date: Fri, 30 Dec 2022 01:37:56 +0100 Subject: [PATCH] allow untagged enums to contain externally tagged enums --- serde/src/private/de.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/serde/src/private/de.rs b/serde/src/private/de.rs index e9c693d4d..97db357dc 100644 --- a/serde/src/private/de.rs +++ b/serde/src/private/de.rs @@ -203,13 +203,16 @@ mod content { // This issue is tracking making some of this stuff public: // https://github.com/serde-rs/serde/issues/741 + #[cfg(feature = "alloc")] + use alloc::vec; + use lib::*; use __private::size_hint; use actually_private; use de::{ self, Deserialize, DeserializeSeed, Deserializer, EnumAccess, Expected, IgnoredAny, - MapAccess, SeqAccess, Unexpected, Visitor, + MapAccess, SeqAccess, Unexpected, VariantAccess, Visitor }; /// Used from generated code to buffer the contents of the Deserializer when @@ -492,13 +495,17 @@ mod content { Ok(Content::Map(vec)) } - fn visit_enum(self, _visitor: V) -> Result + fn visit_enum(self, visitor: V) -> Result where V: EnumAccess<'de>, { - Err(de::Error::custom( - "untagged and internally tagged enums do not support enum input", - )) + // While untagged and internally tagged enums do not support enum input, + // untagged enums can contain externally tagged enums + let (key, value) = visitor.variant()?; + let value = value + .newtype_variant() + .unwrap_or(Content::Unit); + Ok(Content::Map(vec![(key, value)])) } }