From b3ecac00fc070883ced992708905eb6461c7aa9e Mon Sep 17 00:00:00 2001 From: HampusM Date: Wed, 10 Apr 2024 20:39:16 +0200 Subject: feat(ecs-macros): add Sole derive macro --- ecs-macros/src/lib.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'ecs-macros/src') diff --git a/ecs-macros/src/lib.rs b/ecs-macros/src/lib.rs index 8e801f9..17a9be6 100644 --- a/ecs-macros/src/lib.rs +++ b/ecs-macros/src/lib.rs @@ -45,6 +45,38 @@ pub fn component_derive(input: TokenStream) -> TokenStream .into() } +#[proc_macro_derive(Sole)] +pub fn sole_derive(input: TokenStream) -> TokenStream +{ + let item: TypeItem = parse::(input).unwrap().try_into().unwrap(); + + let item_ident = item.ident(); + + quote! { + impl ecs::sole::Sole for #item_ident + { + fn as_any_mut(&mut self) -> &mut dyn std::any::Any + { + self + } + + fn as_any(&self) -> &dyn std::any::Any + { + self + } + } + + impl ecs::type_name::TypeName for #item_ident + { + fn type_name(&self) -> &'static str + { + std::any::type_name::() + } + } + } + .into() +} + enum TypeItem { Struct(ItemStruct), -- cgit v1.2.3-18-g5258