feat(derive): implement derive(Action)

This commit is contained in:
nativerv
2024-02-16 04:02:55 +03:00
parent b88f37457b
commit 8d32bcd62c
2 changed files with 22 additions and 2 deletions
+2
View File
@@ -25,6 +25,8 @@ proc-macro = true
# strum = "0.25.0"
# strum_macros = "0.25.3"
bevy_controls = { path = "./../bevy_controls" }
syn = "1.0"
quote = "1.0"
[dev-dependencies]
env_logger = "0.10.1"
+20 -2
View File
@@ -1,7 +1,25 @@
extern crate proc_macro;
use proc_macro::TokenStream;
use syn;
use quote::quote;
use bevy_controls::contract::{Action, ActionInner};
#[proc_macro_derive(Action)]
pub fn action(_input: TokenStream) -> TokenStream {
todo!("urmom")
pub fn action(input: TokenStream) -> TokenStream {
// Construct a representation of Rust code as a syntax tree
// that we can manipulate
let ast = syn::parse(input).unwrap();
// Build the trait implementation
impl_hello_macro(&ast)
}
fn impl_hello_macro(ast: &syn::DeriveInput) -> TokenStream {
let name = &ast.ident;
let gen = quote! {
impl Action for #name {}
impl ActionInner for #name {}
};
gen.into()
}