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 std derives to SystemParam types #16785

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

Conversation

spectria-limina
Copy link
Contributor

Objective

  • Use Clone on SystemParam, when applicable, in a generic context.

Solution

  • Add some derives

Testing

  • I ran cargo test once.
  • I didn't even look at the output.

@@ -400,6 +401,7 @@ unsafe impl<P: SystemParam, B: SystemParamBuilder<P>> SystemParamBuilder<Vec<P>>
/// set.for_each(|mut query| for mut health in query.iter_mut() {});
/// }
/// ```
#[derive(Debug, Default, Copy, Clone)]
Copy link
Member

Choose a reason for hiding this comment

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

Why Copy here?

@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 labels Dec 12, 2024
@alice-i-cecile
Copy link
Member

It would be helpful to reviewers to briefly explain why Clone was needed on these types.

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

@BD103 BD103 left a comment

Choose a reason for hiding this comment

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

I'm fine with the code changes themselves, but some justification would be appreciated! :)

@BD103 BD103 added S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Dec 13, 2024
@BenjaminBrienen BenjaminBrienen added the D-Straightforward Simple bug fixes and API improvements, docs, test and examples label Dec 25, 2024
@BenjaminBrienen
Copy link
Contributor

If it were just Clone, that would be easier to approve. Why Copy?

@spectria-limina
Copy link
Contributor Author

Sorry for the delay replying.

Types should eagerly implement applicable traits.

My use case was playing around with some dynamic manipulation of builders in order to inject data into a system during state initialization, and my test usage with Local required cloning the builder so that the same builder could be mapped to multiple arguments of a system.

So I think the question is better asked as: why not?

Builder types are only used in the guts of

As for Copy, I think I actually should have made more of them Copy. I don't really see any reason why these shouldn't be Copy when wrapping a Copy type. And [therefore it should] (https://doc.rust-lang.org/std/marker/trait.Copy.html#when-should-my-type-be-copy).

Note that for actual SystemParams, I think Clone or especially Copy wouldn't work because the semantics are tied to the system and it's state. But this is just the builders, and they are basically fancy named closures.

@mockersf
Copy link
Member

So I think the question is better asked as: why not?

More derives mean more build time

And [therefore it should] (https://doc.rust-lang.org/std/marker/trait.Copy.html#when-should-my-type-be-copy).

A lot of people think this advice is wrong. Deriving Copy change the usage of a type from move semantics to copy semantics, and can lead to unexpected behaviour

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-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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants