summaryrefslogtreecommitdiff
path: root/ecs-macros
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2024-04-10 20:39:16 +0200
committerHampusM <hampus@hampusmat.com>2024-04-10 20:39:16 +0200
commitb3ecac00fc070883ced992708905eb6461c7aa9e (patch)
tree7a12b70f458c0cf48b3cd289d1aa9823ae03b6b2 /ecs-macros
parentca51244e9d462c661d29dc60ce5bf6f9056c569b (diff)
feat(ecs-macros): add Sole derive macro
Diffstat (limited to 'ecs-macros')
-rw-r--r--ecs-macros/src/lib.rs32
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),