summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engine-macros/src/lib.rs2
-rw-r--r--engine/src/reflection.rs14
2 files changed, 11 insertions, 5 deletions
diff --git a/engine-macros/src/lib.rs b/engine-macros/src/lib.rs
index b7bbd43..75ff209 100644
--- a/engine-macros/src/lib.rs
+++ b/engine-macros/src/lib.rs
@@ -106,7 +106,7 @@ pub fn reflection_derive(input: TokenStream) -> TokenStream
});
quote! {
- impl #impl_generics #engine_crate_path::reflection::Reflection for
+ unsafe impl #impl_generics #engine_crate_path::reflection::Reflection for
#input_ident #type_generics #where_clause
{
const TYPE_REFLECTION: &#engine_crate_path::reflection::Type =
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 });