You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Objective
Regardless of where we land on #19489, `When` as a system param wrapper
is a touch verbose. In many cases, users may find themselves liberally
applying `When` to their fallible system params. I believe that `If`
maintains the same semantics in a smaller and more readable package, and
therefore should replace `When`.
## Showcase
`When`:
```rs
fn fallible_params(player: When<Single<&mut Velocity, With<Player>>>, gravity: When<Res<Gravity>>) {}
```
`If`:
```rs
fn fallible_params(player: If<Single<&mut Velocity, With<Player>>>, gravity: If<Res<Gravity>>) {}
```
/// failures in validation should be considered a bug in the user's logic that must be immediately addressed (like [`Res`]).
2785
2785
///
2786
2786
/// If `true`, the system should be skipped.
2787
-
/// This is set by wrapping the system param in [`When`],
2787
+
/// This is set by wrapping the system param in [`If`],
2788
2788
/// and indicates that the system is intended to only operate in certain application states.
2789
2789
pubskipped:bool,
2790
2790
@@ -2848,7 +2848,7 @@ impl Display for SystemParamValidationError {
2848
2848
self.message
2849
2849
)?;
2850
2850
if !self.skipped{
2851
-
write!(fmt,"\nIf this is an expected state, wrap the parameter in `Option<T>` and handle `None` when it happens, or wrap the parameter in `When<T>` to skip the system when it happens.")?;
2851
+
write!(fmt,"\nIf this is an expected state, wrap the parameter in `Option<T>` and handle `None` when it happens, or wrap the parameter in `If<T>` to skip the system when it happens.")?;
In order to support fallible systems and parameter-based system skipping like `Single` and `When<T>` in more places, `System::run` and related methods now return a `Result` instead of a plain value.
6
+
In order to support fallible systems and parameter-based system skipping like `Single` and `If<T>` in more places, `System::run` and related methods now return a `Result` instead of a plain value.
7
7
8
8
If you were calling `System::run`, `System::run_unsafe`, `System::run_without_applying_deferred`, or `ReadOnlySystem::run_readonly`, the simplest solution is to `unwrap()` the resulting `Result`.
9
9
The only case where an infallible system will return `Err` is an invalid parameter, such as a missing resource, and those cases used to panic.
0 commit comments