diff options
| author | HampusM <hampus@hampusmat.com> | 2026-04-06 20:55:20 +0200 |
|---|---|---|
| committer | HampusM <hampus@hampusmat.com> | 2026-04-06 20:55:20 +0200 |
| commit | b8e77e54c874c6f47e574d554e04fa8bd8939b54 (patch) | |
| tree | bb9a459838909a728ba6271d99c7c40f81337ac3 /engine/src/reflection.rs | |
| parent | 5853d458ae55443c79976893f822aaed508de013 (diff) | |
Diffstat (limited to 'engine/src/reflection.rs')
| -rw-r--r-- | engine/src/reflection.rs | 14 |
1 files changed, 10 insertions, 4 deletions
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<T: Reflection, const LEN: usize> Reflection for [T; LEN] +unsafe impl<T: Reflection, const LEN: usize> Reflection for [T; LEN] { const TYPE_REFLECTION: &Type = &Type::Array(Array { item_reflection: T::TYPE_REFLECTION, @@ -130,7 +136,7 @@ impl<T: Reflection, const LEN: usize> Reflection for [T; LEN] }); } -impl<T: Reflection> Reflection for &'static [T] +unsafe impl<T: Reflection> Reflection for &'static [T] { const TYPE_REFLECTION: &Type = &Type::Slice(Slice { item_reflection: T::TYPE_REFLECTION }); |
