summaryrefslogtreecommitdiff
path: root/engine/src/reflection.rs
diff options
context:
space:
mode:
Diffstat (limited to 'engine/src/reflection.rs')
-rw-r--r--engine/src/reflection.rs43
1 files changed, 35 insertions, 8 deletions
diff --git a/engine/src/reflection.rs b/engine/src/reflection.rs
index 3ce424e..7c5ee5c 100644
--- a/engine/src/reflection.rs
+++ b/engine/src/reflection.rs
@@ -1,5 +1,6 @@
use std::alloc::Layout;
use std::any::{TypeId, type_name};
+use std::fmt::Debug;
pub use engine_macros::Reflection;
@@ -50,7 +51,15 @@ pub struct StructField
pub byte_offset: usize,
pub type_id: TypeId,
pub type_name: &'static str,
- pub reflection: &'static Reflection,
+ pub get_reflection: FnWithDebug<Option<&'static Reflection>>,
+}
+
+impl StructField
+{
+ pub fn reflection(&self) -> Option<&'static Reflection>
+ {
+ self.get_reflection.get()
+ }
}
#[derive(Debug, Clone)]
@@ -157,14 +166,32 @@ impl<T: With> With for &'static [T]
}
}
-// Used by the Reflection derive macro
-#[doc(hidden)]
-pub mod __private
+#[derive(Clone)]
+pub struct FnWithDebug<Value>
{
- pub const fn get_type_reflection<T>() -> &'static super::Reflection
- where
- T: super::With,
+ func: fn() -> Value,
+}
+
+impl<Value> FnWithDebug<Value>
+{
+ pub const fn new(func: fn() -> Value) -> Self
+ {
+ Self { func }
+ }
+
+ pub fn get(&self) -> Value
+ {
+ (self.func)()
+ }
+}
+
+impl<Value: Debug> Debug for FnWithDebug<Value>
+{
+ fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result
{
- T::REFLECTION
+ formatter
+ .debug_tuple("FnWithDebug")
+ .field(&self.get())
+ .finish()
}
}