bevy/crates/bevy_ecs/src/system
JoJoJet 0c98f9a225 Add AND/OR combinators for run conditions (#7605)
# Objective

Fix #7584.

## Solution

Add an abstraction for creating custom system combinators with minimal boilerplate. Use this to implement AND/OR combinators. Use this to simplify the implementation of `PipeSystem`.

## Example

Feel free to bikeshed on the syntax.

I chose the names `and_then`/`or_else` to emphasize the fact that these short-circuit, while I chose method syntax to empasize that the arguments are *not* treated equally.

```rust
app.add_systems((
    my_system.run_if(resource_exists::<R>().and_then(resource_equals(R(0)))),
    our_system.run_if(resource_exists::<R>().or_else(resource_exists::<S>())),
));
```

---

## Todo

- [ ] Decide on a syntax
- [x] Write docs
- [x] Write tests

## Changelog

+ Added the extension methods `.and_then(...)` and `.or_else(...)` to run conditions, which allows combining run conditions with short-circuiting behavior.
+ Added the trait `Combine`, which can be used with the new `CombinatorSystem` to create system combinators with custom behavior.
2023-02-20 18:16:11 +00:00
..
commands Add a SystemParam primitive for deferred mutations; allow #[derive]ing more types of SystemParam (#6817) 2023-02-06 21:57:57 +00:00
combinator.rs Add AND/OR combinators for run conditions (#7605) 2023-02-20 18:16:11 +00:00
exclusive_function_system.rs implement TypeUuid for primitives and fix multiple-parameter generics having the same TypeUuid (#6633) 2023-02-16 17:09:44 +00:00
exclusive_system_param.rs implement TypeUuid for primitives and fix multiple-parameter generics having the same TypeUuid (#6633) 2023-02-16 17:09:44 +00:00
function_system.rs implement TypeUuid for primitives and fix multiple-parameter generics having the same TypeUuid (#6633) 2023-02-16 17:09:44 +00:00
mod.rs Add AND/OR combinators for run conditions (#7605) 2023-02-20 18:16:11 +00:00
query.rs add UnsafeWorldCell abstraction (#6404) 2023-01-27 00:12:13 +00:00
system.rs Allow piping run conditions (#7547) 2023-02-07 22:22:16 +00:00
system_param.rs implement TypeUuid for primitives and fix multiple-parameter generics having the same TypeUuid (#6633) 2023-02-16 17:09:44 +00:00
system_piping.rs Add AND/OR combinators for run conditions (#7605) 2023-02-20 18:16:11 +00:00