Skip to content

Commit

Permalink
Merge pull request #79 from Aaron1011/fix/type-group
Browse files Browse the repository at this point in the history
Handle nested `syn::Type:::Group`
  • Loading branch information
MarcAntoine-Arnaud authored Jun 1, 2020
2 parents 06dfc42 + 340e75c commit 429c2db
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
29 changes: 29 additions & 0 deletions yaserde/tests/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
6 changes: 5 additions & 1 deletion yaserde_derive/src/common/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand Down

0 comments on commit 429c2db

Please sign in to comment.