feat(derive): implement derive(Action)
This commit is contained in:
@@ -25,6 +25,8 @@ proc-macro = true
|
|||||||
# strum = "0.25.0"
|
# strum = "0.25.0"
|
||||||
# strum_macros = "0.25.3"
|
# strum_macros = "0.25.3"
|
||||||
bevy_controls = { path = "./../bevy_controls" }
|
bevy_controls = { path = "./../bevy_controls" }
|
||||||
|
syn = "1.0"
|
||||||
|
quote = "1.0"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
env_logger = "0.10.1"
|
env_logger = "0.10.1"
|
||||||
|
|||||||
@@ -1,7 +1,25 @@
|
|||||||
extern crate proc_macro;
|
extern crate proc_macro;
|
||||||
|
|
||||||
use proc_macro::TokenStream;
|
use proc_macro::TokenStream;
|
||||||
|
use syn;
|
||||||
|
use quote::quote;
|
||||||
|
use bevy_controls::contract::{Action, ActionInner};
|
||||||
|
|
||||||
#[proc_macro_derive(Action)]
|
#[proc_macro_derive(Action)]
|
||||||
pub fn action(_input: TokenStream) -> TokenStream {
|
pub fn action(input: TokenStream) -> TokenStream {
|
||||||
todo!("urmom")
|
// 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()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user