pub trait IntoCallback<C, E, Params> {
type Callback: Handler<E>;
// Required method
fn into_callback(self, ctx: C, registry: &Registry) -> Self::Callback;
}Expand description
Converts a named function into a Callback.
Identical to IntoHandler but injects &mut C as
the first parameter. ResourceIds resolved via
registry.id::<T>() at call time — panics if any resource is not
registered.
Use IntoCallback when each handler instance needs its own private
state. For stateless handlers (or state shared via World),
prefer IntoHandler.
§Named functions only
Closures do not work with IntoCallback due to Rust’s HRTB inference
limitations with GATs. Use named fn items instead.
§Examples
use nexus_rt::{WorldBuilder, ResMut, IntoCallback, Handler, Resource};
#[derive(Resource)]
struct Counter(u64);
struct TimerCtx { order_id: u64, fires: u64 }
fn on_timeout(ctx: &mut TimerCtx, mut counter: ResMut<Counter>, _event: ()) {
ctx.fires += 1;
counter.0 += ctx.order_id;
}
let mut builder = WorldBuilder::new();
builder.register(Counter(0));
let mut world = builder.build();
let mut cb = on_timeout.into_callback(
TimerCtx { order_id: 42, fires: 0 },
world.registry(),
);
cb.run(&mut world, ());
assert_eq!(cb.ctx.fires, 1);
assert_eq!(world.resource::<Counter>().0, 42);§Panics
Panics if any Param resource is not registered in the
Registry.
Required Associated Types§
Required Methods§
Sourcefn into_callback(self, ctx: C, registry: &Registry) -> Self::Callback
fn into_callback(self, ctx: C, registry: &Registry) -> Self::Callback
Convert this function + context into a Callback.