MovingPtr<'_,B: Bundle> impls Bundle
#20984
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
relevant issue: #20976
Solution
In order to spawn bundles inside
MovingPtrs alongside other bundles, we need to be able to nameMovingPtras a bundle, which the new associated typeNameonBundleallows. This type is basically a canonicalized bundle name-type that allows types likeSpawnRelatedBundleto appear to theBundlesas if they were the bundle they are wrapping:R::RelationshipTarget. (I need to write tests for this).Other parts of the engine, like observers, rely on
Bundlebeing'staticin order to pass around the type without being constrained by lifetimes, which is why I've renamedBundletoBundleImpland madetrait Bundle: BundleImpl + 'static.Not sure how much I like this personally.
Observers only use the associated trait functions of
Bundlewhich shouldn't be affected by the lifetime of the type implementingBundle(I think).An alternative would be to enforce
Bundle::Nameto impl Bundle itself (which it does, since it's just a tuple of bundles) and have the same components/component order asSelfso thatBundles methods are available'static(though usingDynamicBundlethis way would certainly be unsafe). That could allow types carryingBundlesin phantom datas to use the associated functions for component order and ids.