-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Generic SystemParam
impls for Option
and Result
#18766
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Strongly in favor of this. You need a migration guide for |
I thought I added one? Did I put it in the wrong place? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nicely done. Sorry for missing the migration guide before: that looks great.
I'm very pleased about making this pattern more consistent and broadly available.
…n-param # Conflicts: # crates/bevy_ecs/src/system/builder.rs # crates/bevy_ecs/src/system/system_param.rs
# Objective Provide a generic `impl SystemParam for Option<P>` that uses system parameter validation. This immediately gives useful impls for params like `EventReader` and `GizmosState` that are defined in terms of `Res`. It also allows third-party system parameters to be usable with `Option`, which was previously impossible due to orphan rules. Note that this is a behavior change for `Option<Single>`. It currently fails validation if there are multiple matching entities, but with this change it will pass validation and produce `None`. Also provide an impl for `Result<P, SystemParamValidationError>`. This allows systems to inspect the error if necessary, either for bubbling it up or for checking the `skipped` flag. Fixes bevyengine#12634 Fixes bevyengine#14949 Related to bevyengine#18516 ## Solution Add generic `SystemParam` impls for `Option` and `Result`, and remove the impls for specific types. Update documentation and `fallible_params` example with the new semantics for `Option<Single>`.
Objective
Provide a generic
impl SystemParam for Option<P>
that uses system parameter validation. This immediately gives useful impls for params likeEventReader
andGizmosState
that are defined in terms ofRes
. It also allows third-party system parameters to be usable withOption
, which was previously impossible due to orphan rules.Note that this is a behavior change for
Option<Single>
. It currently fails validation if there are multiple matching entities, but with this change it will pass validation and produceNone
.Also provide an impl for
Result<P, SystemParamValidationError>
. This allows systems to inspect the error if necessary, either for bubbling it up or for checking theskipped
flag.Fixes #12634
Fixes #14949
Related to #18516
Solution
Add generic
SystemParam
impls forOption
andResult
, and remove the impls for specific types.Update documentation and
fallible_params
example with the new semantics forOption<Single>
.