summaryrefslogtreecommitdiff
path: root/engine-reflection/src
diff options
context:
space:
mode:
Diffstat (limited to 'engine-reflection/src')
-rw-r--r--engine-reflection/src/lib.rs53
1 files changed, 46 insertions, 7 deletions
diff --git a/engine-reflection/src/lib.rs b/engine-reflection/src/lib.rs
index 3bd6f97..289989c 100644
--- a/engine-reflection/src/lib.rs
+++ b/engine-reflection/src/lib.rs
@@ -45,6 +45,7 @@ pub enum Type
Array(Array),
Slice(Slice),
Literal(Literal),
+ Reference(Reference),
}
impl Type
@@ -72,7 +73,7 @@ impl Type
Self::Struct(struct_type) => struct_type.default_value(),
Self::Enum(enum_type) => enum_type.default_value(),
Self::Literal(literal_type) => literal_type.default_value(),
- Self::Array(_) | Self::Slice(_) => None,
+ Self::Array(_) | Self::Slice(_) | Self::Reference(_) => None,
}
}
@@ -83,7 +84,7 @@ impl Type
Self::Struct(struct_type) => struct_type.has_default_value(),
Self::Enum(enum_type) => enum_type.has_default_value(),
Self::Literal(literal_type) => literal_type.has_default_value(),
- Self::Array(_) | Self::Slice(_) => false,
+ Self::Array(_) | Self::Slice(_) | Self::Reference(_) => false,
}
}
}
@@ -119,6 +120,8 @@ pub struct Enum
/// The enum only contains unit variants.
pub is_unit_only: bool,
+ pub discriminant_size: usize,
+
pub tagged_union: Option<EnumTaggedUnion>,
pub get_default_value: fn() -> Option<DefaultValueFn>,
@@ -225,14 +228,34 @@ impl Field
#[derive(Debug, Clone)]
pub struct Array
{
- pub item_reflection: &'static Type,
+ pub item_type: &'static Type,
+ pub item_layout: Layout,
+ pub get_item_type_name: FnWithDebug<&'static str>,
pub length: usize,
}
+impl Array
+{
+ pub fn item_type_name(&self) -> &'static str
+ {
+ self.get_item_type_name.get()
+ }
+}
+
#[derive(Debug, Clone)]
pub struct Slice
{
- pub item_reflection: &'static Type,
+ pub item_type: &'static Type,
+ pub item_layout: Layout,
+ pub get_item_type_name: FnWithDebug<&'static str>,
+}
+
+impl Slice
+{
+ pub fn item_type_name(&self) -> &'static str
+ {
+ self.get_item_type_name.get()
+ }
}
#[derive(Debug)]
@@ -261,6 +284,12 @@ impl Literal
}
}
+#[derive(Debug)]
+pub struct Reference
+{
+ pub ty: &'static Type,
+}
+
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[non_exhaustive]
pub enum LiteralType
@@ -339,15 +368,25 @@ impl_reflection_for_literals!(
unsafe impl<T: Reflection, const LEN: usize> Reflection for [T; LEN]
{
const TYPE_REFLECTION: &Type = &Type::Array(Array {
- item_reflection: T::TYPE_REFLECTION,
+ item_type: T::TYPE_REFLECTION,
+ item_layout: Layout::new::<T>(),
+ get_item_type_name: FnWithDebug::new(|| type_name::<T>()),
length: LEN,
});
}
unsafe impl<T: Reflection> Reflection for &'static [T]
{
- const TYPE_REFLECTION: &Type =
- &Type::Slice(Slice { item_reflection: T::TYPE_REFLECTION });
+ const TYPE_REFLECTION: &Type = &Type::Slice(Slice {
+ item_type: T::TYPE_REFLECTION,
+ item_layout: Layout::new::<T>(),
+ get_item_type_name: FnWithDebug::new(|| type_name::<T>()),
+ });
+}
+
+unsafe impl<T: Reflection> Reflection for &'static T
+{
+ const TYPE_REFLECTION: &Type = &Type::Reference(Reference { ty: T::TYPE_REFLECTION });
}
#[derive(Clone)]