Skip to content

Commit

Permalink
Clean up deserialize_enum methods on Value and &Value
Browse files Browse the repository at this point in the history
  • Loading branch information
swlynch99 committed May 14, 2024
1 parent 5e83bf7 commit c2540b0
Showing 1 changed file with 22 additions and 24 deletions.
46 changes: 22 additions & 24 deletions src/value/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,18 +311,17 @@ impl<'de> serde::Deserializer<'de> for Value {
where
V: Visitor<'de>,
{
let (variant, value) = match self {
Value::Object(value) => return value.deserialize_enum(name, variants, visitor),
Value::String(variant) => (variant, None),
other => {
return Err(serde::de::Error::invalid_type(
other.unexpected(),
&"string or map",
));
}
};

visitor.visit_enum(EnumDeserializer { variant, value })
match self {
Value::Object(value) => value.deserialize_enum(name, variants, visitor),
Value::String(variant) => visitor.visit_enum(EnumDeserializer {
variant,
value: None,
}),
other => Err(serde::de::Error::invalid_type(
other.unexpected(),
&"string or map",
)),
}
}

#[inline]
Expand Down Expand Up @@ -843,18 +842,17 @@ impl<'de> serde::Deserializer<'de> for &'de Value {
where
V: Visitor<'de>,
{
let (variant, value) = match self {
Value::Object(value) => return value.deserialize_enum(name, variants, visitor),
Value::String(variant) => (variant, None),
other => {
return Err(serde::de::Error::invalid_type(
other.unexpected(),
&"string or map",
));
}
};

visitor.visit_enum(EnumRefDeserializer { variant, value })
match self {
Value::Object(value) => value.deserialize_enum(name, variants, visitor),
Value::String(variant) => visitor.visit_enum(EnumRefDeserializer {
variant,
value: None,
}),
other => Err(serde::de::Error::invalid_type(
other.unexpected(),
&"string or map",
)),
}
}

#[inline]
Expand Down

0 comments on commit c2540b0

Please sign in to comment.