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: &Registry) -> Self::Handler;
}
Expand description

Converts a plain function into a Handler.

Analogous to Bevy’s IntoSystem.

Event E is always the last function parameter. Everything before it is resolved as Param 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.

§Factory functions and use<> (Rust 2024)

If you write a function that takes &Registry and returns impl Handler<E>, Rust 2024 captures the registry borrow in the return type. Add + use<...> listing only the type parameters the handler actually holds:

fn build_handler<C: Config>(
    reg: &Registry,
) -> impl Handler<Order> + use<C> {
    process_order::<C>.into_handler(reg)
}

See the crate-level docs for details.

§Examples

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

#[derive(Resource)]
struct Counter(u64);
#[derive(Resource)]
struct Flag(bool);

fn tick(counter: Res<Counter>, mut flag: ResMut<Flag>, event: u32) {
    if event > 0 {
        flag.0 = true;
    }
}

let mut builder = WorldBuilder::new();
builder.register(Counter(0));
builder.register(Flag(false));

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

Required Associated Types§

Source

type Handler: Handler<E> + 'static

The concrete handler type produced.

Required Methods§

Source

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

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

Implementors§

Source§

impl<E, F: Send + 'static, P0: Param + '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: Send + 'static, P0: Param + 'static, P1: Param + '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: Send + 'static, P0: Param + 'static, P1: Param + 'static, P2: Param + '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: Send + 'static, P0: Param + 'static, P1: Param + 'static, P2: Param + 'static, P3: Param + '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: Send + 'static, P0: Param + 'static, P1: Param + 'static, P2: Param + 'static, P3: Param + 'static, P4: Param + '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: Send + 'static, P0: Param + 'static, P1: Param + 'static, P2: Param + 'static, P3: Param + 'static, P4: Param + 'static, P5: Param + '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: Send + 'static, P0: Param + 'static, P1: Param + 'static, P2: Param + 'static, P3: Param + 'static, P4: Param + 'static, P5: Param + 'static, P6: Param + '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: Send + 'static, P0: Param + 'static, P1: Param + 'static, P2: Param + 'static, P3: Param + 'static, P4: Param + 'static, P5: Param + 'static, P6: Param + 'static, P7: Param + '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(&mut World, E) + Send + 'static> IntoHandler<E, Opaque> for F

Source§

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

Source§

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

Source§

impl<E, H: Handler<E> + 'static> IntoHandler<E, Resolved> for H