feat(derive): implement derive(GameState)
This commit is contained in:
@@ -1,25 +1,29 @@
|
||||
extern crate proc_macro;
|
||||
|
||||
use bevy_controls::contract::{Action, ActionInner};
|
||||
use proc_macro::TokenStream;
|
||||
use quote::quote;
|
||||
use syn;
|
||||
|
||||
#[proc_macro_derive(Action)]
|
||||
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();
|
||||
let ast = syn::parse::<syn::DeriveInput>(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 {}
|
||||
impl bevy_controls::contract::Action for #name {}
|
||||
impl bevy_controls::contract::ActionInner for #name {}
|
||||
};
|
||||
gen.into()
|
||||
}
|
||||
|
||||
#[proc_macro_derive(GameState)]
|
||||
pub fn game_state(input: TokenStream) -> TokenStream {
|
||||
let ast = syn::parse::<syn::DeriveInput>(input).unwrap();
|
||||
|
||||
let name = &ast.ident;
|
||||
let gen = quote! {
|
||||
impl bevy_controls::contract::GameState for #name {}
|
||||
impl bevy_controls::contract::GameStateInner for #name {}
|
||||
};
|
||||
gen.into()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user