OptionalSystemParam

Trait OptionalSystemParam 

Source
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§

Source

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.

Source

fn try_borrow<'s>( world: &'s World, state: &'s mut Self::State, ) -> Option<Self::Param<'s>>

This is used create an instance of the system parame, possibly borrowed from the intermediate parameter state.

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.

Implementors§

Source§

impl<'a, T> OptionalSystemParam for Res<'a, T>
where T: HasSchema,

Source§

impl<'a, T> OptionalSystemParam for ResMut<'a, T>
where T: HasSchema,