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

Merge BuildWorldChildren and BuildChildren traits. #14052

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

yrns
Copy link
Contributor

@yrns yrns commented Jun 27, 2024

Objective

The BuildChildren and BuildWorldChildren traits are mostly identical, so I decided to try and merge them. I'm not sure of the history, maybe they were added before GATs existed.

Solution

  • Add an associated type to BuildChildren which reflects the prior differences between the BuildChildren and BuildWorldChildren traits.
  • Add ChildBuild trait that is the bounds for BuildChildren::Builder, with impls for ChildBuilder and WorldChildBuilder.
  • Remove BuildWorldChildren trait and replace it with an impl of BuildChildren for EntityWorldMut.

Testing

I ran several of the examples that use entity hierarchies, mainly UI.


Changelog

n/a

Migration Guide

n/a

- Add an associated type to `BuildChildren` which reflects the prior
 differences between the `BuildChildren` and `BuildWorldChildren` traits.
- Add `ChildBuild` trait that is the bounds for
`BuildChildren::Builder`, with impls for `ChildBuilder` and `WorldChildBuilder`.
- Remove `BuildWorldChildren` trait and replace it with an impl of `BuildChildren` for
`EntityWorldMut`.
@alice-i-cecile alice-i-cecile added A-ECS Entities, components, systems, and events C-Code-Quality A section of code that is hard to understand or change C-Breaking-Change A breaking change to Bevy's public API that needs to be noted in a migration guide A-Hierarchy Parent-child entity hierarchies labels Jun 27, 2024
@alice-i-cecile
Copy link
Member

Lovely, I was hoping we could do this.

Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the changes. Thanks!

@alice-i-cecile alice-i-cecile added the S-Needs-Review Needs reviewer attention (from anyone!) to move forward label Jun 27, 2024
Copy link
Member

@janhohenheim janhohenheim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea, thanks! Just some minor notes.

crates/bevy_hierarchy/src/child_builder.rs Outdated Show resolved Hide resolved
/// implementations of [`BuildChildren`] as a bound on the [`Builder`](BuildChildren::Builder)
/// associated type. The closure passed to [`BuildChildren::with_children`] accepts an
/// implementation of `ChildBuild` so that children can be spawned via [`ChildBuild::spawn`].
pub trait ChildBuild {
Copy link
Member

@janhohenheim janhohenheim Jun 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth thinking about whether we want the user to be able to implement this trait on their own. The current API implies this and makes adding a new method a breaking change.
I'm personally leaning towards sealing the trait.
What do you think @alice-i-cecile?
Note that the same conversation can be had for BuildChildren.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO we don't bother sealing this but we also just don't really care about adding new methods. This isn't long for the world: complexity isn't worth it here.

@janhohenheim janhohenheim added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jun 29, 2024
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 A-Hierarchy Parent-child entity hierarchies C-Breaking-Change A breaking change to Bevy's public API that needs to be noted in a migration guide 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.

None yet

4 participants