Skip to content

Commit

Permalink
allow untagged enums to contain externally tagged enums
Browse files Browse the repository at this point in the history
  • Loading branch information
ModProg committed Dec 30, 2022
1 parent 61531dd commit c34447b
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions serde/src/private/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ mod content {
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
Expand Down Expand Up @@ -492,13 +492,17 @@ mod content {
Ok(Content::Map(vec))
}

fn visit_enum<V>(self, _visitor: V) -> Result<Self::Value, V::Error>
fn visit_enum<V>(self, visitor: V) -> Result<Self::Value, V::Error>
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)]))
}
}

Expand Down

0 comments on commit c34447b

Please sign in to comment.