- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 4.2k
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-ControversialThere is active debate or serious implications around merging this PRThere is active debate or serious implications around merging this PR
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.
tombh
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-ControversialThere is active debate or serious implications around merging this PRThere is active debate or serious implications around merging this PR