pub trait OptionalSystemParam: SystemParam {
// Required methods
fn try_get_state(world: &World) -> Option<Self::State>;
fn try_borrow<'s>(
world: &'s World,
state: &'s mut Self::State,
) -> Option<Self::Param<'s>>;
}Expand description
Implementing this trait on a SystemParam will allow it to be wrapped in
an Option when used in a system function.
In other words, SystemParam is automatically implemented for Option<T>
where T implements SystemParam and OptionalSystemParam.
You cannot implement OptionalSystemParam on a type that doesn’t
implement SystemParam. Using Option<T> for a SystemParam is
considered as a failsafe for a parameter that can still be gotten short and
fallible. If your type returns an optional value but does not have an
unwrapped version of the parameter value then your option should be stored
inside your type and implemented accordingly in SystemParam.
Required Methods§
Sourcefn try_get_state(world: &World) -> Option<Self::State>
fn try_get_state(world: &World) -> Option<Self::State>
This is called to produce the intermediate state of the system parameter.
This state will be created immediately before the system is run, and will kept alive until the system is done running.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.