summaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
Diffstat (limited to 'engine')
-rw-r--r--engine/src/reflection.rs14
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 });