bevy_ecs: Special-case Entity::PLACEHOLDER
formatting
#15839
Merged
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.
Objective
Oftentimes, users will store an entity on a component or resource. To make this component/resource
Default
-able, they might initialize it withEntity::PLACEHOLDER
. This is sometimes done to avoid the need for anOption<Entity>
, especially if it complicates other logic.For example, it's used in this
Selection
resource to denote "no selection":The problem is that if we try to
Debug
the currentSelection
, we get back:4294967295v1#8589934591
. It's not immediately obvious whether or not the entity is an actual entity or the placeholder.Now while it doesn't take long to realize that this is in fact just the value of
Entity::PLACEHOLDER
, it would be a lot clearer if this was made explicit, especially for these particular use cases.Solution
This PR makes the
Debug
andDisplay
impls forEntity
returnPLACEHOLDER
for theEntity::PLACEHOLDER
constant.Feel free to bikeshed the actual value returned here. I thinkSwapped toPLACEHOLDER
on its own could work too.PLACEHOLDER
fromEntity::PLACEHOLDER
.Testing
You can test locally by running:
Migration Guide
The
Debug
andDisplay
impls forEntity
now returnPLACEHOLDER
for theEntity::PLACEHOLDER
constant. If you had any code relying on these values, you may need to account for this change.