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

Add initial APIs for getting world and commands for child_builders #15416

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

fernanlukban
Copy link
Contributor

Objective

Solution

  • Adds APIs for this

Testing

  • Cargo build
  • working on writing an example that utilizes this

Discussion

For those of you who asked for this, I'm trying to find a concrete use cases where these are useful? Is it because we'd be borrowing commands/world too often? I implemented this not knowing the actual use cases for this, which seemed straightforward, then when I was adding examples and what not I realized when does this actually get used?

@fernanlukban
Copy link
Contributor Author

@benfrankel and @viridia could you take a look at this? Still quite noob at rust so it took me a bit to figure out and reason about the lifetimes properly.

/// });
/// # }
/// ```
impl<'a> ChildBuilder<'a> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
impl<'a> ChildBuilder<'a> {
impl ChildBuilder<'_> {

I believe it should be possible to elide the lifetime here, and then return &mut Commands from commands_mut etc. with no lifetime specified.

/// });
/// }
/// ```
impl<'w> WorldChildBuilder<'w> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
impl<'w> WorldChildBuilder<'w> {
impl WorldChildBuilder<'_> {

Same lifetime elision.


#[test]
fn get_commands_from_child_builder() {
let world = World::default();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why World::default() here and World::new() in the other test?

Comment on lines +1386 to +1387
let mut _world_mut_clone = world_child_builder.world_mut();
let _world_clone = world_child_builder.world();
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd add explicit type annotations here, like let mut _: &mut World = .... Same for the .commands() test.

}

/// Same as above, except non-mutable
pub fn commands(&self) -> &Commands<'a, 'a> {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure there's a use-case for an immutable reference to a Commands. I think something like this might work?

pub fn commands(&mut self) -> Commands { self.commands.reborrow() }

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed, I would just have the one method that returns a mutable commands.

Is there a reason we're not simply returning self.world.commands()?

Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is a method on ChildBuilder, there's no self.world.

@alice-i-cecile alice-i-cecile added A-ECS Entities, components, systems, and events C-Usability A targeted quality-of-life change that makes Bevy easier to use A-Hierarchy Parent-child entity hierarchies S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged D-Straightforward Simple bug fixes and API improvements, docs, test and examples X-Uncontroversial This work is generally agreed upon labels Sep 26, 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-Usability A targeted quality-of-life change that makes Bevy easier to use D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged X-Uncontroversial This work is generally agreed upon
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add world and world_mut methods to WorldChildBuilder
4 participants