From eaff58026be19c068005d6e90bd9e8cbe985b093 Mon Sep 17 00:00:00 2001 From: HampusM Date: Mon, 8 Jun 2026 17:19:46 +0200 Subject: feat(engine): add enum variant field reflection --- engine-reflection/src/lib.rs | 53 ++++++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 17 deletions(-) (limited to 'engine-reflection/src/lib.rs') diff --git a/engine-reflection/src/lib.rs b/engine-reflection/src/lib.rs index ef705a0..53aa953 100644 --- a/engine-reflection/src/lib.rs +++ b/engine-reflection/src/lib.rs @@ -69,23 +69,55 @@ impl Type #[derive(Debug, Clone)] pub struct Struct { - pub fields: &'static [StructField], + pub fields: &'static [Field], } #[derive(Debug, Clone)] -pub struct StructField +pub struct Enum +{ + /// Enum variants in the same order as in the enum definition. + pub variants: &'static [EnumVariant], + + /// The enum only contains unit variants. + pub is_unit_only: bool, +} + +#[derive(Debug, Clone)] +pub struct EnumVariant { pub name: &'static str, + + /// The fields of this variant. If `None`, this variant is a unit variant. + pub fields: Option, +} + +#[derive(Debug, Clone)] +pub enum EnumVariantFields +{ + Named + { + fields: &'static [Field] + }, + Unnamed + { + fields: &'static [Field] + }, +} + +#[derive(Debug, Clone)] +pub struct Field +{ + pub name: Option<&'static str>, pub index: usize, pub layout: Layout, - pub byte_offset: usize, + pub byte_offset: Option, pub type_id: TypeId, pub type_name: &'static str, pub get_type: FnWithDebug>, pub visibility: Visibility, } -impl StructField +impl Field { pub fn type_reflection(&self) -> Option<&'static Type> { @@ -93,19 +125,6 @@ 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