What problem does this solve or what need does it fill?
Working with dynamic collections of components (as might be used in advanced spawning patterns) is very painful at the moment: every straightforward path is blocked due to missing impls. This cannot be fixed in end user code, as they do not own the Component trait, or the common wrapper types like Vec and Box.
What solution would you like?
- Implement
Component for Box<dyn Component>, which uses the box's data as the component.
- Do similarly for
Rc and Arc (and any other common smart pointers).
- Implement
Bundle for IntoIter<Item=Component>, which combined with the above would allow us to use structs like Vec<Box<dyn Component>> as bundles.
Notes:
- This will need to be done for each of the standard storage types, as we cannot vary the associated type found within the trait object.
- In practice, we may need
DynClone for this pattern to actually work, which would probably force a DynComponent trait layer.
What alternative(s) have you considered?
Other possible approaches:
- make
Bundle itself object-safe, obviating 3. I don't think this will be feasible.
- implement
Component for &Component, since we can get these out of our boxes. This doesn't work nicely though, due to the need to clone components out of a standard storage.
#1515 would provide an alternate path to some of the use cases.
Some very limited workarounds may exist using commands (and entity commands) in certain use cases.
What problem does this solve or what need does it fill?
Working with dynamic collections of components (as might be used in advanced spawning patterns) is very painful at the moment: every straightforward path is blocked due to missing impls. This cannot be fixed in end user code, as they do not own the
Componenttrait, or the common wrapper types likeVecandBox.What solution would you like?
ComponentforBox<dyn Component>, which uses the box's data as the component.RcandArc(and any other common smart pointers).BundleforIntoIter<Item=Component>, which combined with the above would allow us to use structs likeVec<Box<dyn Component>>as bundles.Notes:
DynClonefor this pattern to actually work, which would probably force aDynComponenttrait layer.What alternative(s) have you considered?
Other possible approaches:
Bundleitself object-safe, obviating 3. I don't think this will be feasible.Componentfor&Component, since we can get these out of our boxes. This doesn't work nicely though, due to the need to clone components out of a standard storage.#1515 would provide an alternate path to some of the use cases.
Some very limited workarounds may exist using commands (and entity commands) in certain use cases.