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 moreimpl<'w, 's, P: ReadOnlySystemParam + 'static> ReadOnlySystemParam for StaticSystemParam<'w, 's, P>
Auto Trait Implementations§
impl<'w, 's, P> Freeze for StaticSystemParam<'w, 's, P>
impl<'w, 's, P> RefUnwindSafe for StaticSystemParam<'w, 's, P>
impl<'w, 's, P> Send for StaticSystemParam<'w, 's, P>
impl<'w, 's, P> Sync for StaticSystemParam<'w, 's, P>
impl<'w, 's, P> Unpin for StaticSystemParam<'w, 's, P>
impl<'w, 's, P> UnwindSafe for StaticSystemParam<'w, 's, P>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
    T: ?Sized,
 
impl<T> BorrowMut<T> for Twhere
    T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
 
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
    T: Any,
 
impl<T> Downcast for Twhere
    T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
 
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
 
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
 
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
 
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
 
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
 
impl<T> DowncastSync for T
Source§impl<T> IntoResult<T> for T
 
impl<T> IntoResult<T> for T
Source§fn into_result(self) -> Result<T, RunSystemError>
 
fn into_result(self) -> Result<T, RunSystemError>
Source§impl<R> Rng for R
 
impl<R> Rng for R
Source§fn random<T>(&mut self) -> Twhere
    StandardUniform: Distribution<T>,
 
fn random<T>(&mut self) -> Twhere
    StandardUniform: Distribution<T>,
StandardUniform distribution. Read moreSource§fn random_iter<T>(self) -> Iter<StandardUniform, Self, T>
 
fn random_iter<T>(self) -> Iter<StandardUniform, Self, T>
Source§fn random_range<T, R>(&mut self, range: R) -> Twhere
    T: SampleUniform,
    R: SampleRange<T>,
 
fn random_range<T, R>(&mut self, range: R) -> Twhere
    T: SampleUniform,
    R: SampleRange<T>,
Source§fn random_bool(&mut self, p: f64) -> bool
 
fn random_bool(&mut self, p: f64) -> bool
p of being true. Read moreSource§fn random_ratio(&mut self, numerator: u32, denominator: u32) -> bool
 
fn random_ratio(&mut self, numerator: u32, denominator: u32) -> bool
numerator/denominator of being
true. Read moreSource§fn sample<T, D>(&mut self, distr: D) -> Twhere
    D: Distribution<T>,
 
fn sample<T, D>(&mut self, distr: D) -> Twhere
    D: Distribution<T>,
Source§fn sample_iter<T, D>(self, distr: D) -> Iter<D, Self, T>where
    D: Distribution<T>,
    Self: Sized,
 
fn sample_iter<T, D>(self, distr: D) -> Iter<D, Self, T>where
    D: Distribution<T>,
    Self: Sized,
Source§fn gen<T>(&mut self) -> Twhere
    StandardUniform: Distribution<T>,
 
fn gen<T>(&mut self) -> Twhere
    StandardUniform: Distribution<T>,
random to avoid conflict with the new gen keyword in Rust 2024.Rng::random.Source§fn gen_range<T, R>(&mut self, range: R) -> Twhere
    T: SampleUniform,
    R: SampleRange<T>,
 
fn gen_range<T, R>(&mut self, range: R) -> Twhere
    T: SampleUniform,
    R: SampleRange<T>,
random_rangeRng::random_range.Source§impl<R> TryRngCore for R
 
impl<R> TryRngCore for R
Source§type Error = Infallible
 
type Error = Infallible
Source§fn try_next_u32(&mut self) -> Result<u32, <R as TryRngCore>::Error>
 
fn try_next_u32(&mut self) -> Result<u32, <R as TryRngCore>::Error>
u32.Source§fn try_next_u64(&mut self) -> Result<u64, <R as TryRngCore>::Error>
 
fn try_next_u64(&mut self) -> Result<u64, <R as TryRngCore>::Error>
u64.Source§fn try_fill_bytes(
    &mut self,
    dst: &mut [u8],
) -> Result<(), <R as TryRngCore>::Error>
 
fn try_fill_bytes( &mut self, dst: &mut [u8], ) -> Result<(), <R as TryRngCore>::Error>
dest entirely with random data.Source§fn unwrap_mut(&mut self) -> UnwrapMut<'_, Self>
 
fn unwrap_mut(&mut self) -> UnwrapMut<'_, Self>
UnwrapMut wrapper.Source§fn read_adapter(&mut self) -> RngReadAdapter<'_, Self>where
    Self: Sized,
 
fn read_adapter(&mut self) -> RngReadAdapter<'_, Self>where
    Self: Sized,
RngCore to a RngReadAdapter.