From 11857e2ff82aeebb13d41e32e400a9beeae1e20e Mon Sep 17 00:00:00 2001 From: HampusM Date: Thu, 23 Apr 2026 15:16:43 +0200 Subject: feat(engine): add enum reflection --- engine/src/reflection.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'engine/src') diff --git a/engine/src/reflection.rs b/engine/src/reflection.rs index 83bc636..429946b 100644 --- a/engine/src/reflection.rs +++ b/engine/src/reflection.rs @@ -27,11 +27,22 @@ pub unsafe trait Reflection: 'static } } +/// Trait implemented by enums that support runtime reflection on them. +/// +/// # Safety +/// Implementors of this trait must provide accurate reflection information in the +/// `get_variant_reflection` method. +pub unsafe trait EnumReflectionExt: Reflection +{ + fn get_variant_reflection(&self) -> &'static EnumVariant; +} + #[derive(Debug)] #[non_exhaustive] pub enum Type { Struct(Struct), + Enum(Enum), Array(Array), Slice(Slice), Literal(Literal), @@ -46,6 +57,14 @@ impl Type _ => None, } } + + pub const fn as_enum(&self) -> Option<&Enum> + { + match self { + Self::Enum(enum_reflection) => Some(enum_reflection), + _ => None, + } + } } #[derive(Debug, Clone)] @@ -74,6 +93,19 @@ impl StructField } } +#[derive(Debug, Clone)] +pub struct Enum +{ + /// Enum variants in the same order as in the enum definition. + pub variants: &'static [EnumVariant], +} + +#[derive(Debug, Clone)] +pub struct EnumVariant +{ + pub name: &'static str, +} + #[derive(Debug, Clone)] pub struct Array { -- cgit v1.2.3-18-g5258