summaryrefslogtreecommitdiff
path: root/engine-reflection/src
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2026-07-05 01:37:21 +0200
committerHampusM <hampus@hampusmat.com>2026-07-05 01:37:21 +0200
commit377367bc67a9eac69951562aea1cdc5040e20b80 (patch)
tree742b50a7d4e80b0f91d8894e5cfb58f6d2631108 /engine-reflection/src
parent02ee21f4571cda15d4bf0ee42128709cfab0485b (diff)
feat(engine): make Reflection derivable on enums without C or primitive repr
Diffstat (limited to 'engine-reflection/src')
-rw-r--r--engine-reflection/src/lib.rs38
1 files changed, 10 insertions, 28 deletions
diff --git a/engine-reflection/src/lib.rs b/engine-reflection/src/lib.rs
index 2b8d01a..62fa4f5 100644
--- a/engine-reflection/src/lib.rs
+++ b/engine-reflection/src/lib.rs
@@ -135,10 +135,6 @@ pub struct Enum
/// The enum only contains unit variants.
pub is_unit_only: bool,
- pub discriminant_size: usize,
-
- pub tagged_union: Option<EnumTaggedUnion>,
-
pub get_default_value: fn() -> Option<DefaultValueFn>,
pub cast_dyn_any: CastDynAnyFn,
@@ -161,15 +157,6 @@ 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,
@@ -177,8 +164,6 @@ pub struct EnumVariant
/// The fields of this variant. If `None`, this variant is a unit variant.
pub fields: Option<EnumVariantFields>,
- pub discriminant: EnumDiscriminant,
-
pub try_write_new_to: fn(
dst: &mut dyn Any,
fields: &mut dyn Iterator<Item = Box<dyn Any>>,
@@ -206,17 +191,17 @@ pub enum EnumVariantFields
{
Named
{
- fields: &'static [Field]
+ fields: &'static [EnumVariantField]
},
Unnamed
{
- fields: &'static [Field]
+ fields: &'static [EnumVariantField]
},
}
impl EnumVariantFields
{
- pub fn fields(&self) -> &'static [Field]
+ pub fn fields(&self) -> &'static [EnumVariantField]
{
match self {
Self::Named { fields } => fields,
@@ -225,13 +210,14 @@ impl EnumVariantFields
}
}
-/// The discriminant of a enum variant.
-#[derive(Debug, Clone, PartialEq, Eq, Hash)]
-pub struct EnumDiscriminant
+#[derive(Debug, Clone)]
+pub struct EnumVariantField
{
- /// This buffer is the size of a u128/i128 because they are the largest possible enum
- /// discriminant representations.
- pub buf: [u8; size_of::<u128>()],
+ pub name: Option<&'static str>,
+ pub index: usize,
+ pub type_id: TypeId,
+ pub get_type_name: FnWithDebug<&'static str>,
+ pub get_type: FnWithDebug<Option<&'static Type>>,
}
#[derive(Debug, Clone)]
@@ -242,10 +228,6 @@ pub struct Field
pub layout: Layout,
/// Byte offset to the field relative to the start of the type containing it.
- ///
- /// If the type containing the field is a enum variant, this offset is relative to
- /// the payload field of the enum's equivalent tagged union, therefore this offset
- /// will **NOT** include the enum tag
pub byte_offset: usize,
pub type_id: TypeId,