Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle nested syn::Type:::Group #79

Merged
merged 2 commits into from
Jun 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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