Skip to main content

IntoHandler

Trait IntoHandler 

Source
pub trait IntoHandler<E, Params> {
    type Handler: Handler<E> + 'static;

    // Required method
    fn into_handler(self, registry: &mut Registry) -> Self::Handler;
}
Expand description

Converts a plain function into a Handler.

Event E is always the last function parameter. Everything before it is resolved as SystemParam from a Registry.

§Named functions only

Closures do not work with IntoHandler due to Rust’s HRTB inference limitations with GATs. Use named fn items instead. This is the same limitation as Bevy’s system registration.

§Examples

use nexus_rt::{Res, ResMut, IntoHandler, WorldBuilder};

fn tick(counter: Res<u64>, mut flag: ResMut<bool>, event: u32) {
    if event > 0 {
        *flag = true;
    }
}

let mut builder = WorldBuilder::new();
builder.register::<u64>(0);
builder.register::<bool>(false);

let mut handler = tick.into_handler(builder.registry_mut());

Required Associated Types§

Source

type Handler: Handler<E> + 'static

The concrete handler type produced.

Required Methods§

Source

fn into_handler(self, registry: &mut Registry) -> Self::Handler

Convert this function into a handler, resolving parameters from the registry.

Implementors§

Source§

impl<E, F: 'static, P0: SystemParam + 'static> IntoHandler<E, (P0,)> for F
where for<'a> &'a mut F: FnMut(P0, E) + FnMut(P0::Item<'a>, E),

Source§

type Handler = Callback<(), CtxFree<F>, (P0,)>

Source§

impl<E, F: 'static, P0: SystemParam + 'static, P1: SystemParam + 'static> IntoHandler<E, (P0, P1)> for F
where for<'a> &'a mut F: FnMut(P0, P1, E) + FnMut(P0::Item<'a>, P1::Item<'a>, E),

Source§

type Handler = Callback<(), CtxFree<F>, (P0, P1)>

Source§

impl<E, F: 'static, P0: SystemParam + 'static, P1: SystemParam + 'static, P2: SystemParam + 'static> IntoHandler<E, (P0, P1, P2)> for F
where for<'a> &'a mut F: FnMut(P0, P1, P2, E) + FnMut(P0::Item<'a>, P1::Item<'a>, P2::Item<'a>, E),

Source§

impl<E, F: 'static, P0: SystemParam + 'static, P1: SystemParam + 'static, P2: SystemParam + 'static, P3: SystemParam + 'static> IntoHandler<E, (P0, P1, P2, P3)> for F
where for<'a> &'a mut F: FnMut(P0, P1, P2, P3, E) + FnMut(P0::Item<'a>, P1::Item<'a>, P2::Item<'a>, P3::Item<'a>, E),

Source§

impl<E, F: 'static, P0: SystemParam + 'static, P1: SystemParam + 'static, P2: SystemParam + 'static, P3: SystemParam + 'static, P4: SystemParam + 'static> IntoHandler<E, (P0, P1, P2, P3, P4)> for F
where for<'a> &'a mut F: FnMut(P0, P1, P2, P3, P4, E) + FnMut(P0::Item<'a>, P1::Item<'a>, P2::Item<'a>, P3::Item<'a>, P4::Item<'a>, E),

Source§

impl<E, F: 'static, P0: SystemParam + 'static, P1: SystemParam + 'static, P2: SystemParam + 'static, P3: SystemParam + 'static, P4: SystemParam + 'static, P5: SystemParam + 'static> IntoHandler<E, (P0, P1, P2, P3, P4, P5)> for F
where for<'a> &'a mut F: FnMut(P0, P1, P2, P3, P4, P5, E) + FnMut(P0::Item<'a>, P1::Item<'a>, P2::Item<'a>, P3::Item<'a>, P4::Item<'a>, P5::Item<'a>, E),

Source§

impl<E, F: 'static, P0: SystemParam + 'static, P1: SystemParam + 'static, P2: SystemParam + 'static, P3: SystemParam + 'static, P4: SystemParam + 'static, P5: SystemParam + 'static, P6: SystemParam + 'static> IntoHandler<E, (P0, P1, P2, P3, P4, P5, P6)> for F
where for<'a> &'a mut F: FnMut(P0, P1, P2, P3, P4, P5, P6, E) + FnMut(P0::Item<'a>, P1::Item<'a>, P2::Item<'a>, P3::Item<'a>, P4::Item<'a>, P5::Item<'a>, P6::Item<'a>, E),

Source§

impl<E, F: 'static, P0: SystemParam + 'static, P1: SystemParam + 'static, P2: SystemParam + 'static, P3: SystemParam + 'static, P4: SystemParam + 'static, P5: SystemParam + 'static, P6: SystemParam + 'static, P7: SystemParam + 'static> IntoHandler<E, (P0, P1, P2, P3, P4, P5, P6, P7)> for F
where for<'a> &'a mut F: FnMut(P0, P1, P2, P3, P4, P5, P6, P7, E) + FnMut(P0::Item<'a>, P1::Item<'a>, P2::Item<'a>, P3::Item<'a>, P4::Item<'a>, P5::Item<'a>, P6::Item<'a>, P7::Item<'a>, E),

Source§

impl<E, F: FnMut(E) + 'static> IntoHandler<E, ()> for F

Source§

type Handler = Callback<(), CtxFree<F>, ()>