bevy/crates
Guillaume Wafo-Tapa 0e805eb49c
Implement SystemCondition for systems returning Result<bool, BevyError> and Result<(), BevyError> (#19553)
# Objective

Fixes #19403
As described in the issue, the objective is to support the use of
systems returning `Result<(), BevyError>` and
`Result<bool, BevyError>` as run conditions. In these cases, the run
condition would hold on `Ok(())` and `Ok(true)` respectively.


## Solution

`IntoSystem<In, bool, M>` cannot be implemented for systems returning
`Result<(), BevyError>` and `Result<bool, BevyError>` as that would
conflict with their trivial implementation of the trait. That led me to
add a method to the sealed trait `SystemCondition` that does the
conversion. In the original case of a system returning `bool`, the
system is returned as is. With the new types, the system is combined
with `map()` to obtain a `bool`.

By the way, I'm confused as to why `SystemCondition` has a generic `In`
parameter as it is only ever used with `In = ()` as far as I can tell.

## Testing

I added a simple test for both type of system. That's minimal but it
felt enough. I could not picture the more complicated tests passing for
a run condition returning `bool` and failing for the new types.

## Doc

I documenting the change on the page of the trait. I had trouble wording
it right but I'm not sure how to improve it. The phrasing "the condition
returns `true`" which reads naturally is now technically incorrect as
the new types return a `Result`. However, the underlying condition
system that the implementing system turns into does indeed return
`bool`. But talking about the implementation details felt too much.
Another possibility is to use another turn of phrase like "the condition
holds" or "the condition checks out". I've left "the condition returns
`true`" in the documentation of `run_if` and the provided methods for
now.

I'm perplexed about the examples. In the first one, why not implement
the condition directly instead of having a system returning it? Is it
from a time of Bevy where you had to implement your conditions that way?
In that case maybe that should be updated. And in the second example I'm
missing the point entirely. As I stated above, I've only seen conditions
used in contexts where they have no input parameter. Here we create a
condition with an input parameter (cannot be used by `run_if`) and we
are using it with `pipe()` which actually doesn't need our system to
implement `SystemCondition`. Both examples are also calling
`IntoSystem::into_system` which should not be encouraged. What am I
missing?
2025-06-10 00:04:10 +00:00
..
bevy_a11y bevyengine.org -> bevy.org (#19503) 2025-06-05 23:09:28 +00:00
bevy_animation Improve Bevy's double-precision story for third-party crates (#19194) 2025-06-08 02:02:47 +00:00
bevy_anti_aliasing bevyengine.org -> bevy.org (#19503) 2025-06-05 23:09:28 +00:00
bevy_app generic component propagation (#17575) 2025-06-06 00:02:02 +00:00
bevy_asset bevyengine.org -> bevy.org (#19503) 2025-06-05 23:09:28 +00:00
bevy_audio bevyengine.org -> bevy.org (#19503) 2025-06-05 23:09:28 +00:00
bevy_color Improve Bevy's double-precision story for third-party crates (#19194) 2025-06-08 02:02:47 +00:00
bevy_core_pipeline bevyengine.org -> bevy.org (#19503) 2025-06-05 23:09:28 +00:00
bevy_derive bevyengine.org -> bevy.org (#19503) 2025-06-05 23:09:28 +00:00
bevy_dev_tools bevyengine.org -> bevy.org (#19503) 2025-06-05 23:09:28 +00:00
bevy_diagnostic bevyengine.org -> bevy.org (#19503) 2025-06-05 23:09:28 +00:00
bevy_dylib bevyengine.org -> bevy.org (#19503) 2025-06-05 23:09:28 +00:00
bevy_ecs Implement SystemCondition for systems returning Result<bool, BevyError> and Result<(), BevyError> (#19553) 2025-06-10 00:04:10 +00:00
bevy_encase_derive bevyengine.org -> bevy.org (#19503) 2025-06-05 23:09:28 +00:00
bevy_gilrs bevyengine.org -> bevy.org (#19503) 2025-06-05 23:09:28 +00:00
bevy_gizmos bevyengine.org -> bevy.org (#19503) 2025-06-05 23:09:28 +00:00
bevy_gltf bevyengine.org -> bevy.org (#19503) 2025-06-05 23:09:28 +00:00
bevy_image Add missing docs for ImageLoader (#19499) 2025-06-09 19:46:33 +00:00
bevy_input bevyengine.org -> bevy.org (#19503) 2025-06-05 23:09:28 +00:00
bevy_input_focus Remove entity placeholder from observers (#19440) 2025-06-09 19:37:56 +00:00
bevy_internal bevyengine.org -> bevy.org (#19503) 2025-06-05 23:09:28 +00:00
bevy_log bevyengine.org -> bevy.org (#19503) 2025-06-05 23:09:28 +00:00
bevy_macro_utils bevyengine.org -> bevy.org (#19503) 2025-06-05 23:09:28 +00:00
bevy_math Improve Bevy's double-precision story for third-party crates (#19194) 2025-06-08 02:02:47 +00:00
bevy_mesh bevyengine.org -> bevy.org (#19503) 2025-06-05 23:09:28 +00:00
bevy_mikktspace bevyengine.org -> bevy.org (#19503) 2025-06-05 23:09:28 +00:00
bevy_pbr Remove entity placeholder from observers (#19440) 2025-06-09 19:37:56 +00:00
bevy_picking Remove entity placeholder from observers (#19440) 2025-06-09 19:37:56 +00:00
bevy_platform bevyengine.org -> bevy.org (#19503) 2025-06-05 23:09:28 +00:00
bevy_ptr bevyengine.org -> bevy.org (#19503) 2025-06-05 23:09:28 +00:00
bevy_reflect bevyengine.org -> bevy.org (#19503) 2025-06-05 23:09:28 +00:00
bevy_remote Only get valid component ids (#19510) 2025-06-06 20:59:57 +00:00
bevy_render Add extra buffer usages field to MeshAllocator (#19546) 2025-06-09 20:03:57 +00:00
bevy_scene Remove entity placeholder from observers (#19440) 2025-06-09 19:37:56 +00:00
bevy_sprite bevyengine.org -> bevy.org (#19503) 2025-06-05 23:09:28 +00:00
bevy_state bevyengine.org -> bevy.org (#19503) 2025-06-05 23:09:28 +00:00
bevy_tasks bevyengine.org -> bevy.org (#19503) 2025-06-05 23:09:28 +00:00
bevy_text Adding PartialEq to some UI and Text types (#19552) 2025-06-09 20:08:17 +00:00
bevy_time bevyengine.org -> bevy.org (#19503) 2025-06-05 23:09:28 +00:00
bevy_transform bevyengine.org -> bevy.org (#19503) 2025-06-05 23:09:28 +00:00
bevy_ui Adding PartialEq to some UI and Text types (#19552) 2025-06-09 20:08:17 +00:00
bevy_utils bevyengine.org -> bevy.org (#19503) 2025-06-05 23:09:28 +00:00
bevy_window bevyengine.org -> bevy.org (#19503) 2025-06-05 23:09:28 +00:00
bevy_winit Remove entity placeholder from observers (#19440) 2025-06-09 19:37:56 +00:00