pub struct StaticSystemParam<'w, 's, P: SystemParam>(/* private fields */);Expand description
A helper for using system parameters in generic contexts
This type is a SystemParam adapter which always has
Self::Item == Self (ignoring lifetimes for brevity),
no matter the argument SystemParam (P) (other than
that P must be 'static)
This makes it useful for having arbitrary SystemParam type arguments
to function systems, or for generic types using the SystemParam
derive:
use bevy_ecs::system::{SystemParam, StaticSystemParam};
#[derive(SystemParam)]
struct GenericParam<'w,'s, T: SystemParam + 'static> {
field: StaticSystemParam<'w, 's, T>,
}
fn do_thing_generically<T: SystemParam + 'static>(t: StaticSystemParam<T>) {}
fn check_always_is_system<T: SystemParam + 'static>(){
bevy_ecs::system::assert_is_system(do_thing_generically::<T>);
}Note that in a real case you’d generally want
additional bounds on P, for your use of the parameter
to have a reason to be generic.
For example, using this would allow a type to be generic over
whether a resource is accessed mutably or not, with
impls being bounded on P: Deref<Target=MyType>, and
P: DerefMut<Target=MyType> depending on whether the
method requires mutable access or not.
The method which doesn’t use this type will not compile:
fn do_thing_generically<T: SystemParam + 'static>(t: T) {}
#[derive(SystemParam)]
struct GenericParam<'w, 's, T: SystemParam> {
field: T,
// Use the lifetimes in this type, or they will be unbound.
phantom: std::marker::PhantomData<&'w &'s ()>
}Implementations§
Source§impl<'w, 's, P: SystemParam> StaticSystemParam<'w, 's, P>
impl<'w, 's, P: SystemParam> StaticSystemParam<'w, 's, P>
Sourcepub fn into_inner(self) -> SystemParamItem<'w, 's, P>
pub fn into_inner(self) -> SystemParamItem<'w, 's, P>
Get the value of the parameter
Trait Implementations§
Source§impl<'w, 's, P: SystemParam> Deref for StaticSystemParam<'w, 's, P>
impl<'w, 's, P: SystemParam> Deref for StaticSystemParam<'w, 's, P>
Source§impl<'w, 's, P: SystemParam> DerefMut for StaticSystemParam<'w, 's, P>
impl<'w, 's, P: SystemParam> DerefMut for StaticSystemParam<'w, 's, P>
Source§impl<P: SystemParam + 'static> SystemParam for StaticSystemParam<'_, '_, P>
impl<P: SystemParam + 'static> SystemParam for StaticSystemParam<'_, '_, P>
Source§type State = <P as SystemParam>::State
type State = <P as SystemParam>::State
Source§type Item<'world, 'state> = StaticSystemParam<'world, 'state, P>
type Item<'world, 'state> = StaticSystemParam<'world, 'state, P>
Self, instantiated with new lifetimes. Read moreSource§fn init_access(
state: &Self::State,
system_meta: &mut SystemMeta,
component_access_set: &mut FilteredAccessSet,
world: &mut World,
)
fn init_access( state: &Self::State, system_meta: &mut SystemMeta, component_access_set: &mut FilteredAccessSet, world: &mut World, )
World access used by this SystemParamSource§fn apply(state: &mut Self::State, system_meta: &SystemMeta, world: &mut World)
fn apply(state: &mut Self::State, system_meta: &SystemMeta, world: &mut World)
SystemParam’s state.
This is used to apply Commands during ApplyDeferred.Source§fn queue(
state: &mut Self::State,
system_meta: &SystemMeta,
world: DeferredWorld<'_>,
)
fn queue( state: &mut Self::State, system_meta: &SystemMeta, world: DeferredWorld<'_>, )
ApplyDeferred.Source§unsafe fn validate_param(
state: &mut Self::State,
system_meta: &SystemMeta,
world: UnsafeWorldCell<'_>,
) -> Result<(), SystemParamValidationError>
unsafe fn validate_param( state: &mut Self::State, system_meta: &SystemMeta, world: UnsafeWorldCell<'_>, ) -> Result<(), SystemParamValidationError>
Source§unsafe fn get_param<'world, 'state>(
state: &'state mut Self::State,
system_meta: &SystemMeta,
world: UnsafeWorldCell<'world>,
change_tick: Tick,
) -> Self::Item<'world, 'state>
unsafe fn get_param<'world, 'state>( state: &'state mut Self::State, system_meta: &SystemMeta, world: UnsafeWorldCell<'world>, change_tick: Tick, ) -> Self::Item<'world, 'state>
SystemParamFunction. Read more