1use quote::quote;
2use syn::DeriveInput;
3
4#[proc_macro_derive(Userdata)]
5pub fn userdata_derive(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
6 let DeriveInput {
7 ident, generics, ..
8 } = syn::parse_macro_input!(input as DeriveInput);
9
10 if !generics.params.is_empty() {
11 panic!("Userdata derive macro does not support generics");
12 }
13
14 quote! {
15 impl ::lu::Userdata for #ident {
16 fn tag() -> u32 {
17 static TAG: ::std::sync::OnceLock<u32> = ::std::sync::OnceLock::new();
18 *TAG.get_or_init(::lu::unique_tag)
19 }
20
21 fn name() -> &'static str {
22 stringify!(#ident)
23 }
24 }
25 }
26 .into()
27}