Merge pull request #79 from Aaron1011/fix/type-group

Handle nested `syn::Type:::Group`
This commit is contained in:
Marc-Antoine ARNAUD 2020-06-01 17:08:40 +02:00 committed by GitHub
commit 429c2db493
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 1 deletions

View File

@ -110,3 +110,32 @@ fn default_attribute_string() {
serialize_and_validate!(model, content);
deserialize_and_validate!(content, model, XmlStruct);
}
#[test]
fn module_inclusion() {
mod module {
use super::*;
#[derive(Debug, Default, PartialEq, YaDeserialize, YaSerialize)]
#[yaserde(rename = "module")]
pub struct Module {
#[yaserde(attribute)]
pub color: String,
}
}
#[derive(Debug, PartialEq, YaDeserialize, YaSerialize)]
#[yaserde(rename = "base")]
pub struct XmlStruct {
background: module::Module,
}
let content = r#"<base><background color="blue" /></base>"#;
let model = XmlStruct {
background: module::Module {
color: "blue".to_string(),
},
};
serialize_and_validate!(model, content);
deserialize_and_validate!(content, model, XmlStruct);
}

View File

@ -225,7 +225,11 @@ impl From<&syn::Path> for Field {
impl From<&syn::Field> for Field {
fn from(field: &syn::Field) -> Self {
match field.ty {
let mut ty = &field.ty;
while let syn::Type::Group(g) = ty {
ty = &g.elem;
}
match ty {
Path(ref path) => Field::from(&path.path),
_ => panic!("unable to match {:?}", field.ty),
}