bevy icon indicating copy to clipboard operation
bevy copied to clipboard

Implement `Reflect` for `Box<[T]>`

Open porkbrain opened this issue 2 years ago • 1 comments

What problem does this solve or what need does it fill?

For immutable arrays with variable runtime len, it's idiomatic to use Box<[T]> type.

What solution would you like?

Similarly to an array [T; N], I should be able to derive Reflect on types that contain Box<[T]>. I'd send an MR with this feature, except I was not sure whether this type fit better TypeInfo::List or TypeInfo::Array. The issue with the former is that there musn't be any appends, so cannot implement List due to required insert and remove. The issue with the latter is that Typed::type_info` requires the capacity to be known without any reference to self.

What alternative(s) have you considered?

I could use Vec<T>, but I'd prefer Box<[T]>.

porkbrain avatar Jan 27 '24 22:01 porkbrain

I guess its either:

  • adding some TypeInfo::FixedSizeList type (something like that)
  • use TypeInfo::List and override the push method to panic, and defining insert and remove to actually do set_at_index and nullify_at_index (take the element and replace it with some default value)
  • bite the bullet and use Vec<T>

Adamkob12 avatar Jan 28 '24 10:01 Adamkob12