-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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 Clone to common conditions #8060
Conversation
Welcome, new contributor! Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨ |
Strongly in favor of this: let's keep this simple and nonbreaking for now so we can ship it in the point release. Can you add a few tests to assert that distributive_run_if compiles with these common conditions? |
Sure, where should they go? |
I would add them in a |
Oh that probably makes more sense than what I just did, I added a test to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good change.
This doesn't have to be done now, but here's how we can support Clone
for not
:
- Implement
Clone
forCombinatorSystem
when both composite systems areClone
. - Instead of returning
impl Condition<>
fromnot
, return a concrete type (probably a type alias). Then the compiler knows that the returned system isClone
as long as the input system is.
@@ -142,7 +142,7 @@ pub mod common_conditions { | |||
|
|||
/// Generates a [`Condition`](super::Condition)-satisfying closure that returns `true` | |||
/// if the first time the condition is run and false every time after | |||
pub fn run_once() -> impl FnMut() -> bool { | |||
pub fn run_once() -> impl Clone + FnMut() -> bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
readability nit: FnMut is more important here than Clone so IMO it should come first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FnMut() -> bool + Clone
looks weird to me. It makes it look like the function is returning bool + Clone
somehow.
How can we get the concrete type for the closure that does the inversion? |
Ah, I left out a step. You'd have to replace |
@B-Reif unless I hear otherwise I'm going to merge this PR in about 10 hours :) We can add the additional fixes in a follow-up. |
@alice-i-cecile Just fixed the merge conflict, please try again :) |
I take it that because those commits 👆 happened after the PR was merged, they didn't actually make it in? I'm using bevy 0.11 right now, and |
In order for |
Objective
The system configuration
distributive_run_if
requires the given condition to beClone
. This doesn't currently work with the closures returned bycommon_conditions
modules. Partially fixes #8058.Solution
Add
Clone
to the return type of common conditions wherever possible.Caveats
resource_equals
andresource_exists_and_equals
have to dereference the resource they're comparing, these functions would have to specify the resource type to beT: Clone
if we want the returned closure to also beClone
.not
condition takes any arbitrary condition which may or may not beClone
, and the returnedCombinatorSystem
isn'tClone
.I'm not sure how to support
Clone
in these cases. This would likely require some new traits? Open to ideas on this.Changelog
Add
Clone
to the return type of most common run conditions.