mirror of
https://github.com/guilhermewerner/reflection
synced 2025-06-16 13:34:19 +00:00
Update macros
This commit is contained in:
@ -4,21 +4,41 @@
|
||||
|
||||
use proc_macro::TokenStream;
|
||||
use quote::quote;
|
||||
use syn::{parse_macro_input, DeriveInput};
|
||||
use syn::{parse_macro_input, DeriveInput, ItemFn};
|
||||
|
||||
#[proc_macro_derive(Reflect, attributes(property))]
|
||||
pub fn reflect(input: TokenStream) -> TokenStream {
|
||||
let ast = parse_macro_input!(input as DeriveInput);
|
||||
let name = &ast.ident;
|
||||
let class = parse_macro_input!(input as DeriveInput);
|
||||
let name = &class.ident;
|
||||
|
||||
let expanded = quote! {
|
||||
impl Reflect for #name {}
|
||||
unsafe impl Reflect for #name {
|
||||
fn TypeName(&self) -> &'static str {
|
||||
std::any::type_name::<Self>()
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
expanded.into()
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[proc_macro_attribute]
|
||||
pub fn function(attr: TokenStream, item: TokenStream) -> TokenStream {
|
||||
item
|
||||
let func = parse_macro_input!(item as ItemFn);
|
||||
let name = &func.sig.ident;
|
||||
|
||||
let expanded = quote! {
|
||||
#func
|
||||
|
||||
paste::paste! {
|
||||
#[doc(hidden)]
|
||||
pub fn [<__ #name _Client>]() {}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub fn [<__ #name _Server>]() {}
|
||||
}
|
||||
};
|
||||
|
||||
expanded.into()
|
||||
}
|
||||
|
Reference in New Issue
Block a user