Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use an opaque type for EntityCommand::with_entity #11210

Merged
merged 9 commits into from
Jun 26, 2024

Conversation

JoJoJet
Copy link
Member

@JoJoJet JoJoJet commented Jan 4, 2024

Objective

The trait method with_entity is used to add an EntityCommand to the command queue. Currently this method returns WithEntity<C> which pairs a command with an Entity. By replacing this explicit type with an opaque type, implementors can override this default implementation by returning a custom command or closure that does the same thing with a lower memory footprint.

Solution

Return an opaque type from the method. As a bonus this file is now cleaner without the WithEntity boilerplate

@ItsDoot ItsDoot added A-ECS Entities, components, systems, and events C-Code-Quality A section of code that is hard to understand or change M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide labels Jan 4, 2024
Copy link
Contributor

github-actions bot commented Jan 4, 2024

It looks like your PR is a breaking change, but you didn't provide a migration guide.

Could you add some context on what users should update when this change get released in a new version of Bevy?
It will be used to help writing the migration guide for the version. Putting it after a ## Migration Guide will help it get automatically picked up by our tooling.

Copy link
Contributor

github-actions bot commented Jan 4, 2024

Your PR increases Bevy Minimum Supported Rust Version. Please update the rust-version field in the root Cargo.toml file.

1 similar comment
Copy link
Contributor

github-actions bot commented Jan 4, 2024

Your PR increases Bevy Minimum Supported Rust Version. Please update the rust-version field in the root Cargo.toml file.

@Nilirad
Copy link
Contributor

Nilirad commented Jan 12, 2024

Just wanted to know if it is ok to use impl Command as a return type in this case, as the release notes generally discourage using this syntax in public traits.

@JoJoJet
Copy link
Member Author

JoJoJet commented Jan 12, 2024

Just wanted to know if it is ok to use impl Command as a return type in this case, as the release notes generally discourage using this syntax in public traits.

I think the main reason this use is discouraged is due to weirdness surrounding Send bounds and other auto traits. Command already has a Send bound so I think this should be fine.

@JoJoJet JoJoJet removed the M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide label Jun 26, 2024
@JoJoJet
Copy link
Member Author

JoJoJet commented Jun 26, 2024

On further consideration I don't think this is a breaking change. It was not possible to construct or use the WithEntity type in any way other than as a Command, so it was effectively an opaque type

@alice-i-cecile alice-i-cecile added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Jun 26, 2024
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Jun 26, 2024
Merged via the queue into bevyengine:main with commit a4c621a Jun 26, 2024
28 checks passed
@JoJoJet JoJoJet deleted the opaque-with-entity branch June 26, 2024 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Code-Quality A section of code that is hard to understand or change S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants