diff options
| author | HampusM <hampus@hampusmat.com> | 2026-06-17 15:29:22 +0200 |
|---|---|---|
| committer | HampusM <hampus@hampusmat.com> | 2026-06-17 15:29:22 +0200 |
| commit | f82a35702cb85da7ace298960024b773a2da6d85 (patch) | |
| tree | 0263a76cdb02e18a95507a59e70726f73941b57c /engine-reflection | |
| parent | c79f7883c099f1624f9666fb8691ffc5022c1bf5 (diff) | |
feat(engine): add tagged union info to enum reflection
Diffstat (limited to 'engine-reflection')
| -rw-r--r-- | engine-reflection/src/lib.rs | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/engine-reflection/src/lib.rs b/engine-reflection/src/lib.rs index 4e5e8d8..3bd6f97 100644 --- a/engine-reflection/src/lib.rs +++ b/engine-reflection/src/lib.rs @@ -119,8 +119,7 @@ pub struct Enum /// The enum only contains unit variants. pub is_unit_only: bool, - pub discriminant_layout: Layout, - pub fields_layout: Option<Layout>, + pub tagged_union: Option<EnumTaggedUnion>, pub get_default_value: fn() -> Option<DefaultValueFn>, } @@ -141,6 +140,15 @@ impl Enum } #[derive(Debug, Clone)] +pub struct EnumTaggedUnion +{ + pub discriminant_layout: Layout, + pub discriminant_byte_offset: usize, + pub fields_layout: Layout, + pub fields_byte_offset: usize, +} + +#[derive(Debug, Clone)] pub struct EnumVariant { pub name: &'static str, @@ -164,6 +172,17 @@ pub enum EnumVariantFields }, } +impl EnumVariantFields +{ + pub fn fields(&self) -> &'static [Field] + { + match self { + Self::Named { fields } => fields, + Self::Unnamed { fields } => fields, + } + } +} + /// The discriminant of a enum variant. #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct EnumDiscriminant |
