Introduce a dedicated function for generating Field enum
(the enum that represents all fields of a struct)
This commit is contained in:
parent
b6685cf9dd
commit
2a36d11238
@ -965,12 +965,7 @@ fn deserialize_struct(
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
let field_visitor = Stmts(deserialize_generated_identifier(
|
let field_visitor = deserialize_field_identifier(&field_names_idents, cattrs);
|
||||||
&field_names_idents,
|
|
||||||
cattrs,
|
|
||||||
false,
|
|
||||||
None,
|
|
||||||
));
|
|
||||||
|
|
||||||
// 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.
|
||||||
@ -1128,12 +1123,7 @@ fn deserialize_struct_in_place(
|
|||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let field_visitor = Stmts(deserialize_generated_identifier(
|
let field_visitor = deserialize_field_identifier(&field_names_idents, cattrs);
|
||||||
&field_names_idents,
|
|
||||||
cattrs,
|
|
||||||
false,
|
|
||||||
None,
|
|
||||||
));
|
|
||||||
|
|
||||||
let mut_seq = if field_names_idents.is_empty() {
|
let mut_seq = if field_names_idents.is_empty() {
|
||||||
quote!(_)
|
quote!(_)
|
||||||
@ -2052,6 +2042,20 @@ fn deserialize_generated_identifier(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Generates enum and its `Deserialize` implementation that represents each
|
||||||
|
/// non-skipped field of the struct
|
||||||
|
fn deserialize_field_identifier(
|
||||||
|
fields: &[(&str, Ident, &BTreeSet<String>)],
|
||||||
|
cattrs: &attr::Container,
|
||||||
|
) -> Stmts {
|
||||||
|
Stmts(deserialize_generated_identifier(
|
||||||
|
fields,
|
||||||
|
cattrs,
|
||||||
|
false,
|
||||||
|
None,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
// Generates `Deserialize::deserialize` body for an enum with
|
// Generates `Deserialize::deserialize` body for an enum with
|
||||||
// `serde(field_identifier)` or `serde(variant_identifier)` attribute.
|
// `serde(field_identifier)` or `serde(variant_identifier)` attribute.
|
||||||
fn deserialize_custom_identifier(
|
fn deserialize_custom_identifier(
|
||||||
|
Loading…
Reference in New Issue
Block a user