feat(derive): implement derive(GameState)
This commit is contained in:
Generated
+10
@@ -460,6 +460,16 @@ dependencies = [
|
|||||||
"strum_macros",
|
"strum_macros",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bevy_controls_derive"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"bevy_controls",
|
||||||
|
"env_logger",
|
||||||
|
"quote",
|
||||||
|
"syn 1.0.109",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bevy_core"
|
name = "bevy_core"
|
||||||
version = "0.12.1"
|
version = "0.12.1"
|
||||||
|
|||||||
@@ -1,25 +1,29 @@
|
|||||||
extern crate proc_macro;
|
extern crate proc_macro;
|
||||||
|
|
||||||
use bevy_controls::contract::{Action, ActionInner};
|
|
||||||
use proc_macro::TokenStream;
|
use proc_macro::TokenStream;
|
||||||
use quote::quote;
|
use quote::quote;
|
||||||
use syn;
|
use syn;
|
||||||
|
|
||||||
#[proc_macro_derive(Action)]
|
#[proc_macro_derive(Action)]
|
||||||
pub fn action(input: TokenStream) -> TokenStream {
|
pub fn action(input: TokenStream) -> TokenStream {
|
||||||
// Construct a representation of Rust code as a syntax tree
|
let ast = syn::parse::<syn::DeriveInput>(input).unwrap();
|
||||||
// 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 name = &ast.ident;
|
||||||
let gen = quote! {
|
let gen = quote! {
|
||||||
impl Action for #name {}
|
impl bevy_controls::contract::Action for #name {}
|
||||||
impl ActionInner 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()
|
gen.into()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user