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§
Required Methods§
Sourcefn into_handler(self, registry: &Registry) -> Self::Handler
fn into_handler(self, registry: &Registry) -> Self::Handler
Convert this function into a handler, resolving parameters from the registry.