Skip to content

Commit

Permalink
Support flattened enum with default field attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtoth committed Feb 2, 2024
1 parent dce846a commit 2bad167
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions serde_derive/src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2594,11 +2594,36 @@ fn deserialize_map(
}
Some(path) => quote!(#path),
};

let no_variant_expr = if field.attrs.default().is_none() {
let span = field.original.span();
quote_spanned!(span=>
return _serde::__private::Err(
_serde::de::Error::custom(_e.to_string())
);
)
} else {
let is_missing = Expr(expr_is_missing(field, cattrs));
quote!(#is_missing)
};

quote! {
let #name: #field_ty = #func(
_serde::__private::de::FlatMapDeserializer(
&mut __collect,
_serde::__private::PhantomData))?;
let #name: #field_ty = match #func(
_serde::__private::de::FlatMapDeserializer(&mut __collect)) {
_serde::__private::Ok(#name) => #name,
_serde::__private::Err(
_e @ _serde::__private::de::FlatMapDeserializerError::NoVariantFoundInFlattenedData(..)
) => {
#no_variant_expr
}
_serde::__private::Err(
_serde::__private::de::FlatMapDeserializerError::Message(s)
) => {
return _serde::__private::Err(
_serde::de::Error::custom(s)
);
}
};
}
});

Expand Down

0 comments on commit 2bad167

Please sign in to comment.