Add ControlFlow::Continue(()) handling for systems
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 161
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` or I may use a sub-routine that returns a `ControlFlow<()>`.
I would like to be able to use the `?` operator, as [described here](https://doc.rust-lang.org/stable/std/ops/enum.ControlFlow.html) to return early from a system.
## What solution would you like?
Allow for systems to have this in their signature:
```rust
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:
```rust
/// 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:
```rust
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.
Contributor guide
Assessment
This issue has not been assessed yet.