diff options
| author | HampusM <hampus@hampusmat.com> | 2026-07-17 00:32:47 +0200 |
|---|---|---|
| committer | HampusM <hampus@hampusmat.com> | 2026-07-17 00:33:58 +0200 |
| commit | fa92de40a956b732bc5ad7fc6688a924269fa050 (patch) | |
| tree | 8d6d955162adc8c968017cb0bcf27aaf4c1825ab /engine-reflection/src | |
| parent | a4a30c4b53221fa3bbad5a3c998810b9709c106a (diff) | |
feat(engine-reflection): add try_get_len fn to slice reflection
Diffstat (limited to 'engine-reflection/src')
| -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 d9e2c72..76dc71d 100644 --- a/engine-reflection/src/lib.rs +++ b/engine-reflection/src/lib.rs @@ -313,6 +313,7 @@ pub struct Slice pub item_layout: Layout, pub get_item_type_name: FnWithDebug<&'static str>, pub try_get_item: fn(target: &dyn Any, index: usize) -> Result<&dyn Any, GetError>, + pub try_get_len: fn(target: &dyn Any) -> Option<usize>, } impl Slice @@ -477,6 +478,11 @@ unsafe impl<T: Reflection> Reflection for &'static [T] Ok(item) }, + try_get_len: |target| { + let target = target.downcast_ref::<Self>()?; + + Some(target.len()) + }, }); } |
