Merge pull request #79 from Aaron1011/fix/type-group
Handle nested `syn::Type:::Group`
This commit is contained in:
commit
429c2db493
@ -110,3 +110,32 @@ fn default_attribute_string() {
|
|||||||
serialize_and_validate!(model, content);
|
serialize_and_validate!(model, content);
|
||||||
deserialize_and_validate!(content, model, XmlStruct);
|
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);
|
||||||
|
}
|
||||||
|
|||||||
@ -225,7 +225,11 @@ impl From<&syn::Path> for Field {
|
|||||||
|
|
||||||
impl From<&syn::Field> for Field {
|
impl From<&syn::Field> for Field {
|
||||||
fn from(field: &syn::Field) -> Self {
|
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),
|
Path(ref path) => Field::from(&path.path),
|
||||||
_ => panic!("unable to match {:?}", field.ty),
|
_ => panic!("unable to match {:?}", field.ty),
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user