Skip to main content

SystemParam

Trait SystemParam 

Source
pub trait SystemParam {
    type State;
    type Item<'w>;

    // Required methods
    fn init(registry: &Registry) -> Self::State;
    unsafe fn fetch<'w>(
        world: &'w World,
        state: &'w mut Self::State,
    ) -> Self::Item<'w>;
    fn any_changed(state: &Self::State, world: &World) -> bool;

    // Provided method
    fn resource_id(state: &Self::State) -> Option<ResourceId> { ... }
}
Expand description

Trait for types that can be resolved from a Registry at build time and fetched from World at dispatch time.

Build time: init resolves opaque state (e.g. a ResourceId) from the registry. This panics if the required type isn’t registered — giving an early build-time error.

Dispatch time: fetch uses the cached state to produce a reference in ~3 cycles.

Required Associated Types§

Source

type State

Opaque state cached at build time (e.g. ResourceId).

Source

type Item<'w>

The item produced at dispatch time.

Required Methods§

Source

fn init(registry: &Registry) -> Self::State

Resolve state from the registry. Called once at build time.

§Panics

Panics if the required resource is not registered.

Source

unsafe fn fetch<'w>( world: &'w World, state: &'w mut Self::State, ) -> Self::Item<'w>

Fetch the item using cached state.

§Safety
  • state must have been produced by init on the same registry that built the world.
  • Caller ensures no aliasing violations.
Source

fn any_changed(state: &Self::State, world: &World) -> bool

Returns true if any resource this param depends on was modified during the current sequence.

Used by drivers to skip handlers whose inputs haven’t changed.

Provided Methods§

Source

fn resource_id(state: &Self::State) -> Option<ResourceId>

The ResourceId this param accesses, if any.

Returns None for params that don’t access World resources (e.g. Local<T>). Used by Registry::check_access to enforce one borrow per resource per handler.

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.

Implementations on Foreign Types§

Source§

impl SystemParam for ()

Unit impl — event-only handlers with no resource parameters.

Source§

type State = ()

Source§

type Item<'w> = ()

Source§

fn init(_registry: &Registry)

Source§

unsafe fn fetch<'w>(_world: &'w World, _state: &'w mut ())

Source§

fn any_changed(_state: &(), _world: &World) -> bool

Source§

impl<P0: SystemParam> SystemParam for (P0,)

Source§

type State = (<P0 as SystemParam>::State,)

Source§

type Item<'w> = (<P0 as SystemParam>::Item<'w>,)

Source§

fn init(registry: &Registry) -> Self::State

Source§

unsafe fn fetch<'w>( world: &'w World, state: &'w mut Self::State, ) -> Self::Item<'w>

Source§

fn any_changed(state: &Self::State, world: &World) -> bool

Source§

impl<P0: SystemParam, P1: SystemParam> SystemParam for (P0, P1)

Source§

type State = (<P0 as SystemParam>::State, <P1 as SystemParam>::State)

Source§

type Item<'w> = (<P0 as SystemParam>::Item<'w>, <P1 as SystemParam>::Item<'w>)

Source§

fn init(registry: &Registry) -> Self::State

Source§

unsafe fn fetch<'w>( world: &'w World, state: &'w mut Self::State, ) -> Self::Item<'w>

Source§

fn any_changed(state: &Self::State, world: &World) -> bool

Source§

impl<P0: SystemParam, P1: SystemParam, P2: SystemParam> SystemParam for (P0, P1, P2)

Source§

type State = (<P0 as SystemParam>::State, <P1 as SystemParam>::State, <P2 as SystemParam>::State)

Source§

type Item<'w> = (<P0 as SystemParam>::Item<'w>, <P1 as SystemParam>::Item<'w>, <P2 as SystemParam>::Item<'w>)

Source§

fn init(registry: &Registry) -> Self::State

Source§

unsafe fn fetch<'w>( world: &'w World, state: &'w mut Self::State, ) -> Self::Item<'w>

Source§

fn any_changed(state: &Self::State, world: &World) -> bool

Source§

impl<P0: SystemParam, P1: SystemParam, P2: SystemParam, P3: SystemParam> SystemParam for (P0, P1, P2, P3)

Source§

type State = (<P0 as SystemParam>::State, <P1 as SystemParam>::State, <P2 as SystemParam>::State, <P3 as SystemParam>::State)

Source§

type Item<'w> = (<P0 as SystemParam>::Item<'w>, <P1 as SystemParam>::Item<'w>, <P2 as SystemParam>::Item<'w>, <P3 as SystemParam>::Item<'w>)

Source§

fn init(registry: &Registry) -> Self::State

Source§

unsafe fn fetch<'w>( world: &'w World, state: &'w mut Self::State, ) -> Self::Item<'w>

Source§

fn any_changed(state: &Self::State, world: &World) -> bool

Source§

impl<P0: SystemParam, P1: SystemParam, P2: SystemParam, P3: SystemParam, P4: SystemParam> SystemParam for (P0, P1, P2, P3, P4)

Source§

type State = (<P0 as SystemParam>::State, <P1 as SystemParam>::State, <P2 as SystemParam>::State, <P3 as SystemParam>::State, <P4 as SystemParam>::State)

Source§

type Item<'w> = (<P0 as SystemParam>::Item<'w>, <P1 as SystemParam>::Item<'w>, <P2 as SystemParam>::Item<'w>, <P3 as SystemParam>::Item<'w>, <P4 as SystemParam>::Item<'w>)

Source§

fn init(registry: &Registry) -> Self::State

Source§

unsafe fn fetch<'w>( world: &'w World, state: &'w mut Self::State, ) -> Self::Item<'w>

Source§

fn any_changed(state: &Self::State, world: &World) -> bool

Source§

impl<P0: SystemParam, P1: SystemParam, P2: SystemParam, P3: SystemParam, P4: SystemParam, P5: SystemParam> SystemParam for (P0, P1, P2, P3, P4, P5)

Source§

type State = (<P0 as SystemParam>::State, <P1 as SystemParam>::State, <P2 as SystemParam>::State, <P3 as SystemParam>::State, <P4 as SystemParam>::State, <P5 as SystemParam>::State)

Source§

type Item<'w> = (<P0 as SystemParam>::Item<'w>, <P1 as SystemParam>::Item<'w>, <P2 as SystemParam>::Item<'w>, <P3 as SystemParam>::Item<'w>, <P4 as SystemParam>::Item<'w>, <P5 as SystemParam>::Item<'w>)

Source§

fn init(registry: &Registry) -> Self::State

Source§

unsafe fn fetch<'w>( world: &'w World, state: &'w mut Self::State, ) -> Self::Item<'w>

Source§

fn any_changed(state: &Self::State, world: &World) -> bool

Source§

impl<P0: SystemParam, P1: SystemParam, P2: SystemParam, P3: SystemParam, P4: SystemParam, P5: SystemParam, P6: SystemParam> SystemParam for (P0, P1, P2, P3, P4, P5, P6)

Source§

type State = (<P0 as SystemParam>::State, <P1 as SystemParam>::State, <P2 as SystemParam>::State, <P3 as SystemParam>::State, <P4 as SystemParam>::State, <P5 as SystemParam>::State, <P6 as SystemParam>::State)

Source§

type Item<'w> = (<P0 as SystemParam>::Item<'w>, <P1 as SystemParam>::Item<'w>, <P2 as SystemParam>::Item<'w>, <P3 as SystemParam>::Item<'w>, <P4 as SystemParam>::Item<'w>, <P5 as SystemParam>::Item<'w>, <P6 as SystemParam>::Item<'w>)

Source§

fn init(registry: &Registry) -> Self::State

Source§

unsafe fn fetch<'w>( world: &'w World, state: &'w mut Self::State, ) -> Self::Item<'w>

Source§

fn any_changed(state: &Self::State, world: &World) -> bool

Source§

impl<P0: SystemParam, P1: SystemParam, P2: SystemParam, P3: SystemParam, P4: SystemParam, P5: SystemParam, P6: SystemParam, P7: SystemParam> SystemParam for (P0, P1, P2, P3, P4, P5, P6, P7)

Source§

type State = (<P0 as SystemParam>::State, <P1 as SystemParam>::State, <P2 as SystemParam>::State, <P3 as SystemParam>::State, <P4 as SystemParam>::State, <P5 as SystemParam>::State, <P6 as SystemParam>::State, <P7 as SystemParam>::State)

Source§

type Item<'w> = (<P0 as SystemParam>::Item<'w>, <P1 as SystemParam>::Item<'w>, <P2 as SystemParam>::Item<'w>, <P3 as SystemParam>::Item<'w>, <P4 as SystemParam>::Item<'w>, <P5 as SystemParam>::Item<'w>, <P6 as SystemParam>::Item<'w>, <P7 as SystemParam>::Item<'w>)

Source§

fn init(registry: &Registry) -> Self::State

Source§

unsafe fn fetch<'w>( world: &'w World, state: &'w mut Self::State, ) -> Self::Item<'w>

Source§

fn any_changed(state: &Self::State, world: &World) -> bool

Source§

impl<T: 'static> SystemParam for Option<Res<'_, T>>

Source§

type State = Option<ResourceId>

Source§

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

Source§

fn init(registry: &Registry) -> Option<ResourceId>

Source§

unsafe fn fetch<'w>( world: &'w World, state: &'w mut Option<ResourceId>, ) -> Option<Res<'w, T>>

Source§

fn any_changed(state: &Option<ResourceId>, world: &World) -> bool

Source§

fn resource_id(state: &Option<ResourceId>) -> Option<ResourceId>

Source§

impl<T: 'static> SystemParam for Option<ResMut<'_, T>>

Source§

type State = Option<ResourceId>

Source§

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

Source§

fn init(registry: &Registry) -> Option<ResourceId>

Source§

unsafe fn fetch<'w>( world: &'w World, state: &'w mut Option<ResourceId>, ) -> Option<ResMut<'w, T>>

Source§

fn any_changed(state: &Option<ResourceId>, world: &World) -> bool

Source§

fn resource_id(state: &Option<ResourceId>) -> Option<ResourceId>

Implementors§

Source§

impl<T: 'static> SystemParam for Res<'_, T>

Source§

type State = ResourceId

Source§

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

Source§

impl<T: 'static> SystemParam for ResMut<'_, T>

Source§

impl<T: Default + 'static> SystemParam for Local<'_, T>

Source§

type State = T

Source§

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