summaryrefslogtreecommitdiff
path: root/engine-reflection
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2026-06-18 23:30:04 +0200
committerHampusM <hampus@hampusmat.com>2026-06-18 23:30:44 +0200
commit74a038d7eefa389b6d621365998c4bffc6eb8efb (patch)
tree2e06e2582be57940b22420b49473f05e12a02d4a /engine-reflection
parent8848cd0732a7656a2e0913e63d224618082f21df (diff)
feat(engine-reflection): add item layout & item type name to Array & Slice
Diffstat (limited to 'engine-reflection')
-rw-r--r--engine-reflection/src/lib.rs35
1 files changed, 30 insertions, 5 deletions
diff --git a/engine-reflection/src/lib.rs b/engine-reflection/src/lib.rs
index 3bd6f97..dabf4b9 100644
--- a/engine-reflection/src/lib.rs
+++ b/engine-reflection/src/lib.rs
@@ -225,14 +225,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)]
@@ -339,15 +359,20 @@ 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>()),
+ });
}
#[derive(Clone)]