diff options
Diffstat (limited to 'ecs-macros/src')
-rw-r--r-- | ecs-macros/src/lib.rs | 32 |
1 files changed, 32 insertions, 0 deletions
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::<Item>(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::<Self>() + } + } + } + .into() +} + enum TypeItem { Struct(ItemStruct), |