summaryrefslogtreecommitdiff
path: root/engine-reflection
diff options
context:
space:
mode:
Diffstat (limited to 'engine-reflection')
-rw-r--r--engine-reflection/src/lib.rs60
1 files changed, 42 insertions, 18 deletions
diff --git a/engine-reflection/src/lib.rs b/engine-reflection/src/lib.rs
index 5561c9a..8be9e7e 100644
--- a/engine-reflection/src/lib.rs
+++ b/engine-reflection/src/lib.rs
@@ -118,21 +118,45 @@ pub struct Slice
}
#[derive(Debug)]
+#[non_exhaustive]
pub struct Literal
{
pub layout: Layout,
pub type_id: TypeId,
+ pub ty: LiteralType,
pub type_name: fn() -> &'static str,
}
-macro_rules! impl_with_for_literals {
- ($($literal: ty),*) => {
+#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
+#[non_exhaustive]
+pub enum LiteralType
+{
+ U8,
+ I8,
+ U16,
+ I16,
+ U32,
+ I32,
+ U64,
+ I64,
+ U128,
+ I128,
+ F32,
+ F64,
+ Usize,
+ Isize,
+ Str,
+}
+
+macro_rules! impl_reflection_for_literals {
+ ($(($literal_type: ident, $literal: ty)),*) => {
$(
unsafe impl Reflection for $literal
{
const TYPE_REFLECTION: &Type = &Type::Literal(Literal {
layout: Layout::new::<$literal>(),
type_id: TypeId::of::<$literal>(),
+ ty: LiteralType::$literal_type,
type_name: || type_name::<$literal>()
});
}
@@ -140,22 +164,22 @@ macro_rules! impl_with_for_literals {
};
}
-impl_with_for_literals!(
- u8,
- i8,
- u16,
- i16,
- u32,
- i32,
- u64,
- i64,
- u128,
- i128,
- f32,
- f64,
- usize,
- isize,
- &'static str
+impl_reflection_for_literals!(
+ (U8, u8),
+ (I8, i8),
+ (U16, u16),
+ (I16, i16),
+ (U32, u32),
+ (I32, i32),
+ (U64, u64),
+ (I64, i64),
+ (U128, u128),
+ (I128, i128),
+ (F32, f32),
+ (F64, f64),
+ (Usize, usize),
+ (Isize, isize),
+ (Str, &'static str)
);
unsafe impl<T: Reflection, const LEN: usize> Reflection for [T; LEN]