Move deserialize_generated_identifier
out from if because the call is same in both arms
This commit is contained in:
parent
fb3a9e0d7c
commit
bbbd1d24c9
@ -954,28 +954,12 @@ fn deserialize_struct(
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
let (field_visitor, fields_stmt) = if cattrs.has_flatten() {
|
let field_visitor = Stmts(deserialize_generated_identifier(
|
||||||
let field_visitor = deserialize_generated_identifier(&field_names_idents, cattrs, false, None);
|
&field_names_idents,
|
||||||
|
cattrs,
|
||||||
(field_visitor, None)
|
false,
|
||||||
} else {
|
None,
|
||||||
let fields_stmt = {
|
));
|
||||||
let field_names = field_names_idents
|
|
||||||
.iter()
|
|
||||||
.flat_map(|(_, _, aliases)| aliases);
|
|
||||||
|
|
||||||
quote_block! {
|
|
||||||
#[doc(hidden)]
|
|
||||||
const FIELDS: &'static [&'static str] = &[ #(#field_names),* ];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let field_visitor = deserialize_generated_identifier(&field_names_idents, cattrs, false, None);
|
|
||||||
|
|
||||||
(field_visitor, Some(fields_stmt))
|
|
||||||
};
|
|
||||||
let field_visitor = Stmts(field_visitor);
|
|
||||||
let fields_stmt = fields_stmt.map(Stmts);
|
|
||||||
|
|
||||||
// untagged struct variants do not get a visit_seq method. The same applies to
|
// untagged struct variants do not get a visit_seq method. The same applies to
|
||||||
// structs that only have a map representation.
|
// structs that only have a map representation.
|
||||||
@ -1024,6 +1008,19 @@ fn deserialize_struct(
|
|||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let fields_stmt = if cattrs.has_flatten() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
let field_names = field_names_idents
|
||||||
|
.iter()
|
||||||
|
.flat_map(|(_, _, aliases)| aliases);
|
||||||
|
|
||||||
|
Some(quote! {
|
||||||
|
#[doc(hidden)]
|
||||||
|
const FIELDS: &'static [&'static str] = &[ #(#field_names),* ];
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
let visitor_expr = quote! {
|
let visitor_expr = quote! {
|
||||||
__Visitor {
|
__Visitor {
|
||||||
marker: _serde::__private::PhantomData::<#this_type #ty_generics>,
|
marker: _serde::__private::PhantomData::<#this_type #ty_generics>,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user