xml: Also implement unit variants

This commit is contained in:
Lennart
2025-01-18 19:35:19 +01:00
parent ea9f5a711d
commit 39beee2f69
5 changed files with 102 additions and 3 deletions

View File

@@ -67,9 +67,21 @@ pub fn derive_enum_variants(input: proc_macro::TokenStream) -> proc_macro::Token
let input = parse_macro_input!(input as DeriveInput);
match &input.data {
syn::Data::Struct(_) => panic!("Struct not supported, use XmlRootTag instead"),
syn::Data::Struct(_) => panic!("Struct not supported"),
syn::Data::Enum(e) => Enum::parse(&input, e).impl_enum_variants(),
syn::Data::Union(_) => panic!("Union not supported as root"),
syn::Data::Union(_) => panic!("Union not supported"),
}
.into()
}
#[proc_macro_derive(EnumUnitVariants, attributes(xml))]
pub fn derive_enum_unit_variants(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
let input = parse_macro_input!(input as DeriveInput);
match &input.data {
syn::Data::Struct(_) => panic!("Struct not supported"),
syn::Data::Enum(e) => Enum::parse(&input, e).impl_enum_unit_variants(),
syn::Data::Union(_) => panic!("Union not supported"),
}
.into()
}