Impl `Reflect` for `Box<[T]>`
Objective
- Fixes #11570.
Solution
Implements one the solutions proposed in https://github.com/bevyengine/bevy/issues/11570#issuecomment-1913542767.
- Add
FixedLenListas super trait ofList.
Changelog
- Added
FixedLenListtrait as a super trait ofListwhich contains all the methods that did not change the size of the list (e.g.insert,remove, etc.). - Implement
ReflectforBox<[T]>as aFixedLenList.
Migration Guide
-
ReflectRef,ReflectMutandReflectOwnedhave a new variant namedFixedLenList. Accessing a fixed len list from one of these enum may require some boilerplate code :
let list_ref = match b.reflect_ref() {
ReflectRef::FixedLenList(list) => list,
ReflectRef::List(list) => list.as_fixed_len_list(),
_ => unimplemented!(),
};
- Every types that implement
Listmust also implementFixedLenList - The following methods have been migrated from
ListtoFixedLenList-
get -
get_mut -
len -
is_empty -
iter -
clone_dynamic
-
I like this, but I'm not particularly a fan of the
FixedLenListname. But I don't have a better name to suggest.
Yes me too.
Another idea I had is to name the base trait List and the resizable list one something like ResizableList.
But it's probably confusing to rename an existing trait and introduce a new trait with the old name.
name suggestions / general ideas:
-
List->DyanmicList,FixedLenList->List - "Collection"
- "SizedList"
- "DynamicArray"
- "Slice"
but I also think that FixedSizeList / FixedLenList are clear enough - I wouldn't mind them.
name suggestions / general ideas:
[...]
- "SizedList"
Liked the name SizedList, but agree that FixedLenList is a good name too. Another possible name is FixedSizeList if we can't follow with Len for some reason
Why not just Array? In Rust parlance, an array has a static size, so it seems like a natural complement to List being the dynamic one.
Why not just
Array? In Rust parlance, an array has a static size, so it seems like a natural complement toListbeing the dynamic one.
Because an Array means the size is known at compile time, a Box<[T]> is a fixed length list with a size known at runtime instead of compile time.
Ahh... SizedList, perhaps? Though that could have the same problem...
It may be a good idea to start with a simple implementation and revisit later if it's proving a hotspot
Because an Array means the size is known at compile time, a Box<[T]> is a fixed length list with a size known at runtime instead of compile time.
Reflection can only be accessed at runtime, so Array and the proposed FixedLenList both are the same.