From b8e77e54c874c6f47e574d554e04fa8bd8939b54 Mon Sep 17 00:00:00 2001 From: HampusM Date: Mon, 6 Apr 2026 20:55:20 +0200 Subject: feat(engine): make Reflection trait unsafe --- engine/src/reflection.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'engine/src') diff --git a/engine/src/reflection.rs b/engine/src/reflection.rs index 13384fe..83bc636 100644 --- a/engine/src/reflection.rs +++ b/engine/src/reflection.rs @@ -4,7 +4,13 @@ use std::fmt::Debug; pub use engine_macros::Reflection; -pub trait Reflection: 'static +/// Trait implemented by types that support runtime reflection on them. +/// +/// # Safety +/// Implementors of this trait must provide accurate reflection information in the +/// `TYPE_REFLECTION` associated constant and the `type_reflection` and +/// `get_type_reflection` methods. +pub unsafe trait Reflection: 'static { const TYPE_REFLECTION: &Type; @@ -92,7 +98,7 @@ pub struct Literal macro_rules! impl_with_for_literals { ($($literal: ty),*) => { $( - impl Reflection for $literal + unsafe impl Reflection for $literal { const TYPE_REFLECTION: &Type = &Type::Literal(Literal { layout: Layout::new::<$literal>(), @@ -122,7 +128,7 @@ impl_with_for_literals!( &'static str ); -impl Reflection for [T; LEN] +unsafe impl Reflection for [T; LEN] { const TYPE_REFLECTION: &Type = &Type::Array(Array { item_reflection: T::TYPE_REFLECTION, @@ -130,7 +136,7 @@ impl Reflection for [T; LEN] }); } -impl Reflection for &'static [T] +unsafe impl Reflection for &'static [T] { const TYPE_REFLECTION: &Type = &Type::Slice(Slice { item_reflection: T::TYPE_REFLECTION }); -- cgit v1.2.3-18-g5258