-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Add ControlFlow::Continue(()) handling for systems #10874
Copy link
Copy link
Open
Labels
A-ECSEntities, components, systems, and eventsEntities, components, systems, and eventsC-FeatureA new feature, making something new possibleA new feature, making something new possibleX-Needs-SMEThis type of work requires an SME to approve it.This type of work requires an SME to approve it.
Description
What problem does this solve or what need does it fill?
Many a time, I'd run a query and need to exit early. E.g. if some Component is missing or uninitialized and there's no use running the system further. The query may issue out a Result<R, E> or I may use a sub-routine that returns a ControlFlow<()>.
I would like to be able to use the ? operator, as described here to return early from a system.
What solution would you like?
Allow for systems to have this in their signature:
fn system() -> std::ops::ControlFlow<()> {
// Then you call a sub-routine like so:
some_sub_routine_that_can_return_early()?;
...
}What alternative(s) have you considered?
Using a macro to reduce the verbosity of returning early:
/// Unwrap the Continue or return.
///
#[macro_export]
macro_rules! continue_or_return {
( $e:expr ) => {
match $e {
std::ops::ControlFlow::Continue(x) => x,
std::ops::ControlFlow::Break(_) => return,
}
};
}
pub use continue_or_return;And use like so:
fn system() {
// Then you call a sub-routine like so:
continue_or_return!(some_sub_routine_that_can_return_early());
...
}Additional context
I'm on bevy 0.10.1, haven't looked in the latest version to see if this is a problem.
Also I don't know the inner workings of bevy, and if this may be impossible for some internal reason.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-ECSEntities, components, systems, and eventsEntities, components, systems, and eventsC-FeatureA new feature, making something new possibleA new feature, making something new possibleX-Needs-SMEThis type of work requires an SME to approve it.This type of work requires an SME to approve it.