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

Implement std::ops::Not for ShouldRun #2444

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions crates/bevy_ecs/src/schedule/run_criteria.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ pub enum ShouldRun {
NoAndCheckAgain,
}

impl std::ops::Not for ShouldRun {
Copy link
Member

Choose a reason for hiding this comment

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

I'm not certain that this should be the Not operator. I think an associated function called 'invert' or something might make more sense.

(Also I don't think rust-analyzer jumps to Not implementations yet (requires at least rust-lang/rust-analyzer#4558 iirc), so the weird factor is quite high and it's not very inspectible)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could it have both and then one just calls another?

type Output = Self;

fn not(self) -> Self {
match self {
ShouldRun::Yes => ShouldRun::No,
ShouldRun::No => ShouldRun::Yes,
ShouldRun::YesAndCheckAgain => ShouldRun::NoAndCheckAgain,
ShouldRun::NoAndCheckAgain => ShouldRun::YesAndCheckAgain,
}
}
}

pub(crate) struct BoxedRunCriteria {
criteria_system: Option<BoxedSystem<(), ShouldRun>>,
initialized: bool,
Expand Down