Skip to main content

SystemParam

Trait SystemParam 

Source
pub trait SystemParam {
    type Item<'a>;
    type State: Default + 'static;

    // Required method
    fn fetch<'a>(
        state: &'a mut Self::State,
        world: &'a World,
        resources: &'a Resources,
    ) -> Self::Item<'a>;

    // Provided method
    fn requires() -> Vec<RequiredResource> { ... }
}
Expand description

Trait implemented for each valid system parameter type.

The macro-generated [impl_system!] blanket implementations use this to fetch each parameter from the world and resources before calling the system function. State is per-system storage owned by the FunctionSystem itself (as opposed to Item, which only lives for the duration of one call) — this is what lets Local persist between runs.

Required Associated Types§

Source

type Item<'a>

Source

type State: Default + 'static

Required Methods§

Source

fn fetch<'a>( state: &'a mut Self::State, world: &'a World, resources: &'a Resources, ) -> Self::Item<'a>

Provided Methods§

Source

fn requires() -> Vec<RequiredResource>

Resource types this parameter unconditionally needs present to avoid panicking. Used by App to validate — before running a non-convergent stage’s systems — that every hard requirement is already satisfied, failing fast with a clear message instead of panicking deep inside whichever system happens to run first.

Empty by default; only hard requirements (bare Res/ResMut) contribute an entry. Option<Res<T>>/Option<ResMut<T>> tolerate absence and deliberately opt out of this check.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl SystemParam for &'static World

Source§

type Item<'a> = &'a World

Source§

type State = ()

Source§

fn fetch<'a>( _state: &'a mut Self::State, world: &'a World, _resources: &'a Resources, ) -> Self::Item<'a>

Source§

impl<T> SystemParam for Option<Res<'static, T>>
where T: 'static + Sync + Send,

Source§

type Item<'a> = Option<Res<'a, T>>

Source§

type State = ()

Source§

fn fetch<'a>( _state: &'a mut Self::State, world: &'a World, resource: &'a Resources, ) -> Self::Item<'a>

Source§

impl<T> SystemParam for Option<ResMut<'static, T>>
where T: 'static + Sync + Send,

Source§

type Item<'a> = Option<ResMut<'a, T>>

Source§

type State = ()

Source§

fn fetch<'a>( _state: &'a mut Self::State, world: &'a World, resource: &'a Resources, ) -> Self::Item<'a>

Implementors§

Source§

impl SystemParam for &'static Resources

Source§

type Item<'a> = &'a Resources

Source§

type State = ()

Source§

impl SystemParam for Commands<'static>

Source§

type Item<'a> = Commands<'a>

Source§

type State = ()

Source§

impl<Q> SystemParam for Query<'static, Q>
where Q: Query + 'static,

Source§

type Item<'a> = Query<'a, Q>

Source§

type State = ()

Source§

impl<T> SystemParam for Local<'static, T>
where T: Default + Send + Sync + 'static,

Source§

type Item<'a> = Local<'a, T>

Source§

type State = T

Source§

impl<T> SystemParam for Res<'static, T>
where T: 'static + Sync + Send,

Source§

type Item<'a> = Res<'a, T>

Source§

type State = ()

Source§

impl<T> SystemParam for ResMut<'static, T>
where T: 'static + Sync + Send,

Source§

type Item<'a> = ResMut<'a, T>

Source§

type State = ()