summaryrefslogtreecommitdiff
path: root/engine/src/reflection.rs
diff options
context:
space:
mode:
Diffstat (limited to 'engine/src/reflection.rs')
-rw-r--r--engine/src/reflection.rs32
1 files changed, 32 insertions, 0 deletions
diff --git a/engine/src/reflection.rs b/engine/src/reflection.rs
index 83bc636..429946b 100644
--- a/engine/src/reflection.rs
+++ b/engine/src/reflection.rs
@@ -27,11 +27,22 @@ pub unsafe trait Reflection: 'static
}
}
+/// Trait implemented by enums that support runtime reflection on them.
+///
+/// # Safety
+/// Implementors of this trait must provide accurate reflection information in the
+/// `get_variant_reflection` method.
+pub unsafe trait EnumReflectionExt: Reflection
+{
+ fn get_variant_reflection(&self) -> &'static EnumVariant;
+}
+
#[derive(Debug)]
#[non_exhaustive]
pub enum Type
{
Struct(Struct),
+ Enum(Enum),
Array(Array),
Slice(Slice),
Literal(Literal),
@@ -46,6 +57,14 @@ impl Type
_ => None,
}
}
+
+ pub const fn as_enum(&self) -> Option<&Enum>
+ {
+ match self {
+ Self::Enum(enum_reflection) => Some(enum_reflection),
+ _ => None,
+ }
+ }
}
#[derive(Debug, Clone)]
@@ -75,6 +94,19 @@ impl StructField
}
#[derive(Debug, Clone)]
+pub struct Enum
+{
+ /// Enum variants in the same order as in the enum definition.
+ pub variants: &'static [EnumVariant],
+}
+
+#[derive(Debug, Clone)]
+pub struct EnumVariant
+{
+ pub name: &'static str,
+}
+
+#[derive(Debug, Clone)]
pub struct Array
{
pub item_reflection: &'static Type,