PookieBuns commented on code in PR #458:
URL: https://github.com/apache/avro-rs/pull/458#discussion_r2791292555
##########
avro/src/serde/de.rs:
##########
@@ -799,14 +850,26 @@ impl<'de> de::Deserializer<'de> for Deserializer<'de> {
Value::Record(fields) =>
visitor.visit_enum(EnumDeserializer::new(fields)),
Value::String(field) =>
visitor.visit_enum(EnumUnitDeserializer::new(field)),
Value::Union(idx, inner) => {
- if (*idx as usize) < variants.len() {
+ // if we came here from a some, we need to check if we are
deserializing a
+ // non-newtype enum
+ if self.deserializing_some
+ && let Value::Enum(_index, field) = inner.deref()
+ && variants.contains(&&**field)
+ {
+ return
visitor.visit_enum(EnumUnitDeserializer::new(field));
+ }
+ // Assume `null` is the first branch if deserializing some so
decrement the variant index
+ let variant_idx = (*idx as usize)
+ .checked_sub(usize::from(self.deserializing_some))
+ .ok_or_else(|| Details::GetNull(inner.deref().clone()))?;
Review Comment:
Do we want to add an Error variant here to communicate more clearly that
deserializing some when null isn't first isn't supported? Right now it just
tells the user Expects null for 0th when deserializing some
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]