Skip to main content

Param

Trait Param 

Source
pub trait Param {
    type State: Send;
    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>;

    // 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.

Analogous to Bevy’s SystemParam.

Two-phase resolution:

  1. Build timeinit 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.
  2. Dispatch timefetch uses the cached state to produce a reference via a single pointer deref — zero framework overhead.

§Built-in impls

ParamStateDescription
Res<T>ResourceIdShared read
ResMut<T>ResourceIdExclusive write
Option<Res<T>>Option<ResourceId>Optional shared read
Option<ResMut<T>>Option<ResourceId>Optional exclusive write
Local<T>TPer-handler state (not in World)
RegistryRef()Read-only registry access
()()Event-only handlers
Tuples of paramsTuple of statesUp to 8 params

Required Associated Types§

Source

type State: Send

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

Send is required because state is stored in handler types (Callback), and handlers must be Send (they live in World, which is Send).

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.

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 Param 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§

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

Source§

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

Source§

type Item<'w> = (<P0 as Param>::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§

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

Source§

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

Source§

type Item<'w> = (<P0 as Param>::Item<'w>, <P1 as Param>::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§

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

Source§

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

Source§

type Item<'w> = (<P0 as Param>::Item<'w>, <P1 as Param>::Item<'w>, <P2 as Param>::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§

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

Source§

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

Source§

type Item<'w> = (<P0 as Param>::Item<'w>, <P1 as Param>::Item<'w>, <P2 as Param>::Item<'w>, <P3 as Param>::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§

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

Source§

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

Source§

type Item<'w> = (<P0 as Param>::Item<'w>, <P1 as Param>::Item<'w>, <P2 as Param>::Item<'w>, <P3 as Param>::Item<'w>, <P4 as Param>::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§

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

Source§

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

Source§

type Item<'w> = (<P0 as Param>::Item<'w>, <P1 as Param>::Item<'w>, <P2 as Param>::Item<'w>, <P3 as Param>::Item<'w>, <P4 as Param>::Item<'w>, <P5 as Param>::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§

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

Source§

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

Source§

type Item<'w> = (<P0 as Param>::Item<'w>, <P1 as Param>::Item<'w>, <P2 as Param>::Item<'w>, <P3 as Param>::Item<'w>, <P4 as Param>::Item<'w>, <P5 as Param>::Item<'w>, <P6 as Param>::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§

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

Source§

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

Source§

type Item<'w> = (<P0 as Param>::Item<'w>, <P1 as Param>::Item<'w>, <P2 as Param>::Item<'w>, <P3 as Param>::Item<'w>, <P4 as Param>::Item<'w>, <P5 as Param>::Item<'w>, <P6 as Param>::Item<'w>, <P7 as Param>::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§

impl<T: Resource> Param 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 resource_id(state: &Option<ResourceId>) -> Option<ResourceId>

Source§

impl<T: Resource> Param 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 resource_id(state: &Option<ResourceId>) -> Option<ResourceId>

Implementors§

Source§

impl Param for Shutdown<'_>

Source§

type State = ()

Source§

type Item<'w> = Shutdown<'w>

Source§

impl Param for RegistryRef<'_>

Source§

impl Param for Seq

Source§

type State = ()

Source§

type Item<'w> = Seq

Source§

impl Param for SeqMut<'_>

Source§

type State = ()

Source§

type Item<'w> = SeqMut<'w>

Source§

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

Source§

type State = T

Source§

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

Source§

impl<T: Resource> Param for Res<'_, T>

Source§

type State = ResourceId

Source§

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

Source§

impl<T: Resource> Param for ResMut<'_, T>