Skip to content

Commit

Permalink
Merge pull request #169 from jondo2010/fix_field_from_pathsegment
Browse files Browse the repository at this point in the history
Make `From<PathSegment> for Field` handle a corner case
  • Loading branch information
MarcAntoine-Arnaud authored Jan 3, 2024
2 parents 0d088dc + 99a7323 commit 6f434c8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
17 changes: 17 additions & 0 deletions yaserde/tests/deserializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1084,3 +1084,20 @@ fn de_attribute_sequence() {
//serialize_and_validate!(model, content);
deserialize_and_validate!(content, model, Outer);
}

#[test]
fn de_nested_macro_rules() {
init!();

macro_rules! float_attrs {
($type:ty) => {
#[derive(Default, PartialEq, Debug, YaDeserialize)]
pub struct Outer{
#[yaserde(attribute)]
pub inner: Option<$type>,
}
};
}

float_attrs!(f32);
}
15 changes: 12 additions & 3 deletions yaserde_derive/src/common/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,20 @@ impl From<&syn::Field> for Field {
impl From<&syn::PathSegment> for Field {
fn from(path_segment: &syn::PathSegment) -> Self {
if let syn::PathArguments::AngleBracketed(ref args) = path_segment.arguments {
if let Some(syn::GenericArgument::Type(Path(ref path))) = args.args.first() {
return Field::from(&path.path);
match args.args.first() {
Some(syn::GenericArgument::Type(Path(ref path))) => {
return Field::from(&path.path);
},
Some(syn::GenericArgument::Type(syn::Type::Group(syn::TypeGroup { elem, ..}))) => {
if let syn::Type::Path(ref group) = elem.as_ref() {
return Field::from(&group.path);
}
},
_ => unimplemented!("unable to match '{:?}'", args.args.first()),
}
}
unimplemented!()

unimplemented!("unable to match '{}'", quote!{#path_segment})
}
}

Expand Down

0 comments on commit 6f434c8

Please sign in to comment.