summaryrefslogtreecommitdiff
path: root/engine-macros/src/reflection/enum_impl.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2026-07-17 00:31:02 +0200
committerHampusM <hampus@hampusmat.com>2026-07-17 00:31:02 +0200
commita4a30c4b53221fa3bbad5a3c998810b9709c106a (patch)
treea05de329855f934caa62be2667b6d6ea52a7b3cd /engine-macros/src/reflection/enum_impl.rs
parentee5daec60b373210cb5b8de93959394b4b605382 (diff)
feat(engine): add immutable try_get* fns to reflection
Diffstat (limited to 'engine-macros/src/reflection/enum_impl.rs')
-rw-r--r--engine-macros/src/reflection/enum_impl.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/engine-macros/src/reflection/enum_impl.rs b/engine-macros/src/reflection/enum_impl.rs
index 37abc34..14d91a7 100644
--- a/engine-macros/src/reflection/enum_impl.rs
+++ b/engine-macros/src/reflection/enum_impl.rs
@@ -352,6 +352,29 @@ fn generate_variants<'a>(
Ok(())
},
+ try_get_field: |target, field_index| { {
+ #![allow(unreachable_code)]
+
+ use std::any::Any;
+ use #engine_crate_path::reflection::GetError;
+
+ let target = target
+ .downcast_ref::<Self>()
+ .ok_or(GetError::WrongTargetType)?;
+
+ let #variant_pattern = target else {
+ return Err(GetError::WrongTargetEnumVariant);
+ };
+
+ let field: &dyn Any = match field_index {
+ #field_index_match_arms
+ _ => {
+ return Err(GetError::IndexOutOfBounds);
+ }
+ };
+
+ Ok(field)
+ } },
try_get_field_mut: |target, field_index| { {
#![allow(unreachable_code)]