diff options
| author | HampusM <hampus@hampusmat.com> | 2026-07-17 00:34:46 +0200 |
|---|---|---|
| committer | HampusM <hampus@hampusmat.com> | 2026-07-17 00:34:46 +0200 |
| commit | c9cc58a0736c78fb4ead7895173fe443f8f073fe (patch) | |
| tree | 5453ef8ae639d620fe632e6b1e89db5e2f77011b /engine-reflection/src/lib.rs | |
| parent | fa92de40a956b732bc5ad7fc6688a924269fa050 (diff) | |
feat(engine-reflection): add try_deref fn to reference reflection
Diffstat (limited to 'engine-reflection/src/lib.rs')
| -rw-r--r-- | engine-reflection/src/lib.rs | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/engine-reflection/src/lib.rs b/engine-reflection/src/lib.rs index 76dc71d..dedfee7 100644 --- a/engine-reflection/src/lib.rs +++ b/engine-reflection/src/lib.rs @@ -356,6 +356,7 @@ pub struct Reference { pub ty: &'static Type, pub cast_dyn_any: CastDynAnyFn, + pub try_deref: fn(target: &dyn Any) -> Option<&dyn Any>, } #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] @@ -491,6 +492,11 @@ unsafe impl<T: Reflection> Reflection for &'static T const TYPE_REFLECTION: &Type = &Type::Reference(Reference { ty: T::TYPE_REFLECTION, cast_dyn_any: |ptr| ptr.cast::<Self>(), + try_deref: |target| { + let target = target.downcast_ref::<Self>()?; + + Some(*target) + }, }); } |
