Skip to content

Commit

Permalink
Merge pull request #165 from rakaly/smallvec
Browse files Browse the repository at this point in the history
Support duplicated derive deserialization for array types
  • Loading branch information
nickbabcock authored Nov 17, 2024
2 parents 3572b95 + 0c75f9e commit c22dd71
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions jomini_derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ proc-macro = true
trybuild = { version = "1.0", features = ["diff"] }
serde = "1"
serde_json = "1"
smallvec = { version = "1.13", features = ["serde", "union"] }

[dependencies]
syn = "1"
Expand Down
12 changes: 10 additions & 2 deletions jomini_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,16 @@ pub fn derive(input: TokenStream) -> TokenStream {

let farg = &args[0];

quote! {
#match_arm => { (#name).push(serde::de::MapAccess::next_value::<#farg>(&mut __map)?); }
match farg {
syn::GenericArgument::Type(Type::Array(type_array)) => {
let elem = &type_array.elem;
quote! {
#match_arm => { (#name).push(serde::de::MapAccess::next_value::<#elem>(&mut __map)?); }
}
},
_ => quote! {
#match_arm => { (#name).push(serde::de::MapAccess::next_value::<#farg>(&mut __map)?); }
}
}
}
});
Expand Down

0 comments on commit c22dd71

Please sign in to comment.