Skip to main content

If

Struct If 

pub struct If<T>(pub T);
Expand description

A [SystemParam] that wraps another parameter and causes its system to skip instead of failing when the parameter is invalid.

§Example

// This system will fail if `SomeResource` is not present.
fn fails_on_missing_resource(res: Res<SomeResource>) {}

// This system will skip without error if `SomeResource` is not present.
fn skips_on_missing_resource(res: If<Res<SomeResource>>) {
    // The inner parameter is available using `Deref`
    let some_resource: &SomeResource = &res;
}

Tuple Fields§

§0: T

Implementations§

§

impl<T> If<T>

pub fn into_inner(self) -> T

Returns the inner T.

The inner value is pub, so you can also obtain it by destructuring the parameter:

fn skips_on_missing_resource(If(res): If<Res<SomeResource>>) {
    let some_resource: Res<SomeResource> = res;
}

Trait Implementations§

§

impl<T> Debug for If<T>
where T: Debug,

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl<T> Deref for If<T>

§

type Target = T

The resulting type after dereferencing.
§

fn deref(&self) -> &<If<T> as Deref>::Target

Dereferences the value.
§

impl<T> DerefMut for If<T>

§

fn deref_mut(&mut self) -> &mut <If<T> as Deref>::Target

Mutably dereferences the value.
§

impl<T> SystemParam for If<T>
where T: SystemParam,

§

type State = <T as SystemParam>::State

Used to store data which persists across invocations of a system.
§

type Item<'world, 'state> = If<<T as SystemParam>::Item<'world, 'state>>

The item type returned when constructing this system param. The value of this associated type should be Self, instantiated with new lifetimes. Read more
§

fn init_state(world: &mut World) -> <If<T> as SystemParam>::State

Creates a new instance of this param’s State.
§

fn init_access( state: &<If<T> as SystemParam>::State, system_meta: &mut SystemMeta, component_access_set: &mut FilteredAccessSet, world: &mut World, )

Registers any World access used by this [SystemParam]. Read more
§

unsafe fn get_param<'world, 'state>( state: &'state mut <If<T> as SystemParam>::State, system_meta: &SystemMeta, world: UnsafeWorldCell<'world>, change_tick: Tick, ) -> Result<<If<T> as SystemParam>::Item<'world, 'state>, SystemParamValidationError>

Creates a parameter to be passed into a SystemParamFunction. Read more
§

fn apply( state: &mut <If<T> as SystemParam>::State, system_meta: &SystemMeta, world: &mut World, )

Applies any deferred mutations stored in this [SystemParam]’s state. This is used to apply Commands during ApplyDeferred.
§

fn queue( state: &mut <If<T> as SystemParam>::State, system_meta: &SystemMeta, world: DeferredWorld<'_>, )

Queues any deferred mutations to be applied at the next ApplyDeferred.
§

impl<P, B> SystemParamBuilder<If<P>> for IfBuilder<B>
where P: SystemParam, B: SystemParamBuilder<P>,

§

fn build(self, world: &mut World) -> <If<P> as SystemParam>::State

Registers any World access used by this [SystemParam] and creates a new instance of this param’s State.
§

fn build_state(self, world: &mut World) -> SystemState<P>

Create a [SystemState] from a SystemParamBuilder. To create a system, call [SystemState::build_system] on the result.
§

fn build_system<Marker, In, Out, Func>( self, func: Func, ) -> IntoBuilderSystem<Marker, In, Out, Func, Self>
where Self: 'static, Func: SystemParamFunction<Marker, Param = P>,

Create a System from a SystemParamBuilder directly. Read more
§

impl<T> ReadOnlySystemParam for If<T>
where T: ReadOnlySystemParam,

Auto Trait Implementations§

§

impl<T> Freeze for If<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for If<T>
where T: RefUnwindSafe,

§

impl<T> Send for If<T>
where T: Send,

§

impl<T> Sync for If<T>
where T: Sync,

§

impl<T> Unpin for If<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for If<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for If<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> IntoResult<T> for T

§

fn into_result(self) -> Result<T, RunSystemError>

Converts this type into the system output type.
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> ConditionalSend for T
where T: Send,