summaryrefslogtreecommitdiff
path: root/engine-ecs-macros
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2026-06-07 00:41:15 +0200
committerHampusM <hampus@hampusmat.com>2026-06-07 01:20:04 +0200
commit3f099cddf16f2e7e002cc24217ed3cc5da422156 (patch)
treee6ed78738b3b9fff8f4502d4ed909380b9bebf75 /engine-ecs-macros
parent582128a649abc2f460ca00f45571deaf28dd526e (diff)
feat(engine-ecs): add component reflection support
Diffstat (limited to 'engine-ecs-macros')
-rw-r--r--engine-ecs-macros/src/lib.rs40
1 files changed, 40 insertions, 0 deletions
diff --git a/engine-ecs-macros/src/lib.rs b/engine-ecs-macros/src/lib.rs
index 3eb02dd..a304706 100644
--- a/engine-ecs-macros/src/lib.rs
+++ b/engine-ecs-macros/src/lib.rs
@@ -98,6 +98,46 @@ pub fn component_derive(input: TokenStream) -> TokenStream
*#id_var_ident
}
+ fn type_reflection() -> Option<&'static #ecs_path::reflection::Type>
+ {
+ struct SpecializationTarget<T>(std::marker::PhantomData<T>);
+
+ trait HasReflection
+ {
+ fn type_reflection(&self)
+ -> Option<&'static #ecs_path::reflection::Type>;
+ }
+
+ trait NoReflection
+ {
+ fn type_reflection(&self)
+ -> Option<&'static #ecs_path::reflection::Type>;
+ }
+
+ impl<T> NoReflection for &SpecializationTarget<T>
+ {
+ fn type_reflection(&self)
+ -> Option<&'static #ecs_path::reflection::Type>
+ {
+ None
+ }
+ }
+
+ impl<T> HasReflection for SpecializationTarget<T>
+ where
+ T: #ecs_path::reflection::Reflection
+ {
+ fn type_reflection(&self)
+ -> Option<&'static #ecs_path::reflection::Type>
+ {
+ Some(T::type_reflection())
+ }
+ }
+
+ (&SpecializationTarget::<Self>(std::marker::PhantomData))
+ .type_reflection()
+ }
+
fn name(&self) -> &'static str
{
std::any::type_name::<Self>()