diff options
| author | HampusM <hampus@hampusmat.com> | 2026-04-06 20:48:36 +0200 |
|---|---|---|
| committer | HampusM <hampus@hampusmat.com> | 2026-04-06 20:48:36 +0200 |
| commit | 5853d458ae55443c79976893f822aaed508de013 (patch) | |
| tree | 02555763fda13d9dfb4fee00802dad205265144d /engine/src/reflection.rs | |
| parent | 942df064017258a92eee1a14cd613c6aec983dc8 (diff) | |
refactor(engine): improve names of reflection types & items
Diffstat (limited to 'engine/src/reflection.rs')
| -rw-r--r-- | engine/src/reflection.rs | 82 |
1 files changed, 26 insertions, 56 deletions
diff --git a/engine/src/reflection.rs b/engine/src/reflection.rs index 7c5ee5c..13384fe 100644 --- a/engine/src/reflection.rs +++ b/engine/src/reflection.rs @@ -4,20 +4,26 @@ use std::fmt::Debug; pub use engine_macros::Reflection; -pub trait With: 'static +pub trait Reflection: 'static { - const REFLECTION: &Reflection; + const TYPE_REFLECTION: &Type; - fn reflection() -> &'static Reflection + fn type_reflection() -> &'static Type where - Self: Sized; + Self: Sized, + { + Self::TYPE_REFLECTION + } - fn get_reflection(&self) -> &'static Reflection; + fn get_type_reflection(&self) -> &'static Type + { + Self::TYPE_REFLECTION + } } #[derive(Debug)] #[non_exhaustive] -pub enum Reflection +pub enum Type { Struct(Struct), Array(Array), @@ -25,7 +31,7 @@ pub enum Reflection Literal(Literal), } -impl Reflection +impl Type { pub const fn as_struct(&self) -> Option<&Struct> { @@ -51,28 +57,28 @@ pub struct StructField pub byte_offset: usize, pub type_id: TypeId, pub type_name: &'static str, - pub get_reflection: FnWithDebug<Option<&'static Reflection>>, + pub get_type: FnWithDebug<Option<&'static Type>>, } impl StructField { - pub fn reflection(&self) -> Option<&'static Reflection> + pub fn type_reflection(&self) -> Option<&'static Type> { - self.get_reflection.get() + self.get_type.get() } } #[derive(Debug, Clone)] pub struct Array { - pub item_reflection: &'static Reflection, + pub item_reflection: &'static Type, pub length: usize, } #[derive(Debug, Clone)] pub struct Slice { - pub item_reflection: &'static Reflection, + pub item_reflection: &'static Type, } #[derive(Debug)] @@ -86,25 +92,13 @@ pub struct Literal macro_rules! impl_with_for_literals { ($($literal: ty),*) => { $( - impl With for $literal + impl Reflection for $literal { - const REFLECTION: &Reflection = &Reflection::Literal(Literal { + const TYPE_REFLECTION: &Type = &Type::Literal(Literal { layout: Layout::new::<$literal>(), type_id: TypeId::of::<$literal>(), type_name: || type_name::<$literal>() }); - - fn reflection() -> &'static Reflection - where - Self: Sized - { - Self::REFLECTION - } - - fn get_reflection(&self) -> &'static Reflection - { - Self::reflection() - } } )* }; @@ -128,42 +122,18 @@ impl_with_for_literals!( &'static str ); -impl<T: With, const LEN: usize> With for [T; LEN] +impl<T: Reflection, const LEN: usize> Reflection for [T; LEN] { - const REFLECTION: &Reflection = &Reflection::Array(Array { - item_reflection: T::REFLECTION, + const TYPE_REFLECTION: &Type = &Type::Array(Array { + item_reflection: T::TYPE_REFLECTION, length: LEN, }); - - fn reflection() -> &'static Reflection - where - Self: Sized, - { - Self::REFLECTION - } - - fn get_reflection(&self) -> &'static Reflection - { - Self::reflection() - } } -impl<T: With> With for &'static [T] +impl<T: Reflection> Reflection for &'static [T] { - const REFLECTION: &Reflection = - &Reflection::Slice(Slice { item_reflection: T::REFLECTION }); - - fn reflection() -> &'static Reflection - where - Self: Sized, - { - Self::REFLECTION - } - - fn get_reflection(&self) -> &'static Reflection - { - Self::reflection() - } + const TYPE_REFLECTION: &Type = + &Type::Slice(Slice { item_reflection: T::TYPE_REFLECTION }); } #[derive(Clone)] |
