Skip to content

Commit

Permalink
Support flattened enum with default attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtoth committed Feb 3, 2024
1 parent 3e02958 commit 9b7b794
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 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() && cattrs.default().is_none() {
let span = field.original.span();
quote_spanned!(span=>
return _serde::__private::Err(
_serde::de::Error::custom(_e)
);
)
} else {
let is_missing = Expr(expr_is_missing(field, cattrs));
quote!(#is_missing)
};

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

Expand Down

0 comments on commit 9b7b794

Please sign in to comment.