diff options
Diffstat (limited to 'engine-reflection/src/lib.rs')
| -rw-r--r-- | engine-reflection/src/lib.rs | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/engine-reflection/src/lib.rs b/engine-reflection/src/lib.rs index 600c511..9f347fa 100644 --- a/engine-reflection/src/lib.rs +++ b/engine-reflection/src/lib.rs @@ -91,14 +91,15 @@ impl Type } #[inline] - pub fn cast_dyn_any(&self, ptr: NonNull<c_void>) -> Option<NonNull<dyn Any>> { + pub fn cast_dyn_any(&self, ptr: NonNull<c_void>) -> Option<NonNull<dyn Any>> + { match self { Self::Struct(struct_type) => Some((struct_type.cast_dyn_any)(ptr)), Self::Enum(enum_type) => Some((enum_type.cast_dyn_any)(ptr)), Self::Literal(literal_type) => Some((literal_type.cast_dyn_any)(ptr)), Self::Array(array_type) => Some((array_type.cast_dyn_any)(ptr)), Self::Reference(ref_type) => Some((ref_type.cast_dyn_any)(ptr)), - Self::Slice(_) => None + Self::Slice(_) => None, } } } @@ -108,7 +109,7 @@ pub struct Struct { pub fields: &'static [Field], pub get_default_value: fn() -> Option<DefaultValueFn>, - pub cast_dyn_any: CastDynAnyFn + pub cast_dyn_any: CastDynAnyFn, } impl Struct @@ -140,7 +141,7 @@ pub struct Enum pub tagged_union: Option<EnumTaggedUnion>, pub get_default_value: fn() -> Option<DefaultValueFn>, - pub cast_dyn_any: CastDynAnyFn + pub cast_dyn_any: CastDynAnyFn, } impl Enum @@ -218,8 +219,11 @@ pub struct Field pub index: usize, 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, this offset will include the enum tag + /// 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, @@ -248,7 +252,7 @@ pub struct Array pub item_layout: Layout, pub get_item_type_name: FnWithDebug<&'static str>, pub length: usize, - pub cast_dyn_any: CastDynAnyFn + pub cast_dyn_any: CastDynAnyFn, } impl Array @@ -284,7 +288,7 @@ pub struct Literal pub ty: LiteralType, pub type_name: fn() -> &'static str, pub get_default_value: fn() -> Option<DefaultValueFn>, - pub cast_dyn_any: CastDynAnyFn + pub cast_dyn_any: CastDynAnyFn, } impl Literal @@ -306,7 +310,7 @@ impl Literal pub struct Reference { pub ty: &'static Type, - pub cast_dyn_any: CastDynAnyFn + pub cast_dyn_any: CastDynAnyFn, } #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] @@ -392,7 +396,7 @@ unsafe impl<T: Reflection, const LEN: usize> Reflection for [T; LEN] item_layout: Layout::new::<T>(), get_item_type_name: FnWithDebug::new(|| type_name::<T>()), length: LEN, - cast_dyn_any: |ptr| ptr.cast::<Self>() + cast_dyn_any: |ptr| ptr.cast::<Self>(), }); } @@ -409,7 +413,7 @@ unsafe impl<T: Reflection> Reflection for &'static T { const TYPE_REFLECTION: &Type = &Type::Reference(Reference { ty: T::TYPE_REFLECTION, - cast_dyn_any: |ptr| ptr.cast::<Self>() + cast_dyn_any: |ptr| ptr.cast::<Self>(), }); } |
