diff options
Diffstat (limited to 'engine-macros/src/reflection/struct_impl.rs')
| -rw-r--r-- | engine-macros/src/reflection/struct_impl.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/engine-macros/src/reflection/struct_impl.rs b/engine-macros/src/reflection/struct_impl.rs index 1cd9fb8..0ba426d 100644 --- a/engine-macros/src/reflection/struct_impl.rs +++ b/engine-macros/src/reflection/struct_impl.rs @@ -142,6 +142,24 @@ fn gen_impl( #get_default_value_fn }, cast_dyn_any: |ptr| ptr.cast::<Self>(), + try_get_field: |target, field_index| { { + #![allow(unreachable_code)] + + let target = target + .downcast_ref::<Self>() + .ok_or(GetError::WrongTargetType)?; + + let #struct_pattern = target; + + 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)] |
