Less horrible logic for missing fields that unconditionally return error
This commit is contained in:
parent
697234517d
commit
6475e73b05
@ -2539,13 +2539,9 @@ fn deserialize_map_in_place(
|
|||||||
.map(|&(field, ref name)| {
|
.map(|&(field, ref name)| {
|
||||||
let missing_expr = expr_is_missing(field, cattrs);
|
let missing_expr = expr_is_missing(field, cattrs);
|
||||||
// If missing_expr unconditionally returns an error, don't try
|
// If missing_expr unconditionally returns an error, don't try
|
||||||
// to assign its value to self.place. Maybe this could be handled
|
// to assign its value to self.place.
|
||||||
// more elegantly.
|
if field.attrs.default().is_none() && cattrs.default().is_none()
|
||||||
if missing_expr
|
&& field.attrs.deserialize_with().is_some()
|
||||||
.as_ref()
|
|
||||||
.into_tokens()
|
|
||||||
.to_string()
|
|
||||||
.starts_with("return ")
|
|
||||||
{
|
{
|
||||||
let missing_expr = Stmts(missing_expr);
|
let missing_expr = Stmts(missing_expr);
|
||||||
quote! {
|
quote! {
|
||||||
|
@ -738,6 +738,16 @@ pub enum Default {
|
|||||||
Path(syn::ExprPath),
|
Path(syn::ExprPath),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default {
|
||||||
|
#[cfg(feature = "deserialize_in_place")]
|
||||||
|
pub fn is_none(&self) -> bool {
|
||||||
|
match *self {
|
||||||
|
Default::None => true,
|
||||||
|
Default::Default | Default::Path(_) => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Field {
|
impl Field {
|
||||||
/// Extract out the `#[serde(...)]` attributes from a struct field.
|
/// Extract out the `#[serde(...)]` attributes from a struct field.
|
||||||
pub fn from_ast(
|
pub fn from_ast(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user