Merge pull request #169 from jondo2010/fix_field_from_pathsegment

Make `From<PathSegment> for Field` handle a corner case
This commit is contained in:
Marc-Antoine ARNAUD 2024-01-03 17:42:04 +01:00 committed by GitHub
commit 6f434c84cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 3 deletions

View File

@ -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);
}

View File

@ -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})
}
}