diff options
| -rw-r--r-- | engine-macros/src/reflection/field.rs | 9 | ||||
| -rw-r--r-- | engine-reflection/src/lib.rs | 7 |
2 files changed, 10 insertions, 6 deletions
diff --git a/engine-macros/src/reflection/field.rs b/engine-macros/src/reflection/field.rs index 8572875..7d4e301 100644 --- a/engine-macros/src/reflection/field.rs +++ b/engine-macros/src/reflection/field.rs @@ -1,4 +1,4 @@ -use quote::{quote, ToTokens}; +use quote::quote; use crate::reflection::visibility::generate as generate_visibility; @@ -29,9 +29,6 @@ pub fn generate( let field_byte_offset = (options.gen_get_byte_offset)(field); - // since std::any::type_name as const is not stable yet - let field_type_name = field_type.to_token_stream().to_string(); - let field_vis = options.field_vis_override.as_ref().unwrap_or(&field.vis); let field_reflection_vis = generate_visibility(field_vis, &engine_crate_path); @@ -43,7 +40,9 @@ pub fn generate( layout: std::alloc::Layout::new::<#field_type>(), byte_offset: #field_byte_offset, type_id: std::any::TypeId::of::<#field_type>(), - type_name: #field_type_name, + get_type_name: #engine_crate_path::reflection::FnWithDebug::new(|| { + std::any::type_name::<#field_type>() + }), get_type: #engine_crate_path::reflection::FnWithDebug::new(|| { struct SpecializationTarget<Field>(std::marker::PhantomData<Field>); diff --git a/engine-reflection/src/lib.rs b/engine-reflection/src/lib.rs index c884edb..bad26df 100644 --- a/engine-reflection/src/lib.rs +++ b/engine-reflection/src/lib.rs @@ -127,13 +127,18 @@ pub struct Field pub byte_offset: usize, pub type_id: TypeId, - pub type_name: &'static str, + pub get_type_name: FnWithDebug<&'static str>, pub get_type: FnWithDebug<Option<&'static Type>>, pub visibility: Visibility, } impl Field { + pub fn type_name(&self) -> &'static str + { + self.get_type_name.get() + } + pub fn type_reflection(&self) -> Option<&'static Type> { self.get_type.get() |
