Initial work on supporting structs as map with unknown field collection

This commit is contained in:
Armin Ronacher
2018-03-14 11:36:01 +01:00
parent 7ad836e6a9
commit 5a91ac5ba5
2 changed files with 101 additions and 2 deletions
+11
View File
@@ -63,6 +63,7 @@ impl<'a> Container<'a> {
}
};
let mut have_collection_field = false;
match data {
Data::Enum(ref mut variants) => for variant in variants {
variant.attrs.rename_by_rule(attrs.rename_all());
@@ -71,10 +72,20 @@ impl<'a> Container<'a> {
}
},
Data::Struct(_, ref mut fields) => for field in fields {
if field.ident.is_some() && field.ident.as_ref() == attrs.unknown_fields_into() {
field.attrs.mark_as_collection_field();
have_collection_field = true;
}
field.attrs.rename_by_rule(attrs.rename_all());
},
}
if attrs.unknown_fields_into().is_some() && !have_collection_field {
cx.error(format!("#[serde(unknown_fields_into)] was defined but target \
field `{}` does not exist",
attrs.unknown_fields_into().unwrap()));
}
let item = Container {
ident: item.ident,
attrs: attrs,