diff options
Diffstat (limited to 'engine/src/reflection.rs')
| -rw-r--r-- | engine/src/reflection.rs | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/engine/src/reflection.rs b/engine/src/reflection.rs index 5bd2aef..3ce424e 100644 --- a/engine/src/reflection.rs +++ b/engine/src/reflection.rs @@ -1,5 +1,5 @@ use std::alloc::Layout; -use std::any::TypeId; +use std::any::{TypeId, type_name}; pub use engine_macros::Reflection; @@ -14,14 +14,25 @@ pub trait With: 'static fn get_reflection(&self) -> &'static Reflection; } -#[derive(Debug, Clone)] +#[derive(Debug)] #[non_exhaustive] pub enum Reflection { Struct(Struct), Array(Array), Slice(Slice), - Literal, + Literal(Literal), +} + +impl Reflection +{ + pub const fn as_struct(&self) -> Option<&Struct> + { + match self { + Self::Struct(struct_reflection) => Some(struct_reflection), + _ => None, + } + } } #[derive(Debug, Clone)] @@ -55,12 +66,24 @@ pub struct Slice pub item_reflection: &'static Reflection, } +#[derive(Debug)] +pub struct Literal +{ + pub layout: Layout, + pub type_id: TypeId, + pub type_name: fn() -> &'static str, +} + macro_rules! impl_with_for_literals { ($($literal: ty),*) => { $( impl With for $literal { - const REFLECTION: &Reflection = &Reflection::Literal; + const REFLECTION: &Reflection = &Reflection::Literal(Literal { + layout: Layout::new::<$literal>(), + type_id: TypeId::of::<$literal>(), + type_name: || type_name::<$literal>() + }); fn reflection() -> &'static Reflection where |
