Skip to main content

Callback

Struct Callback 

Source
pub struct Callback<C, F, Params: SystemParam> {
    pub ctx: C,
    /* private fields */
}
Expand description

Unified dispatch type. Stores per-callback context alongside pre-resolved resource access.

Both implement Handler<E>.

§Examples

use nexus_rt::{WorldBuilder, ResMut, IntoCallback, Handler};

struct Ctx { count: u64 }

fn handler(ctx: &mut Ctx, mut val: ResMut<u64>, event: u32) {
    *val += event as u64;
    ctx.count += 1;
}

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

let mut cb = handler.into_callback(Ctx { count: 0 }, world.registry_mut());
cb.run(&mut world, 10u32);

assert_eq!(cb.ctx.count, 1);
assert_eq!(*world.resource::<u64>(), 10);

Fields§

§ctx: C

Per-callback owned state. Accessible outside dispatch.

Trait Implementations§

Source§

impl<C: 'static, E, F: FnMut(&mut C, E) + 'static> Handler<E> for Callback<C, F, ()>

Source§

fn run(&mut self, _world: &mut World, event: E)

Run this handler with the given event.
Source§

fn inputs_changed(&self, _world: &World) -> bool

Returns true if any input resource was modified this sequence. Read more
Source§

fn name(&self) -> &'static str

Returns the handler’s name. Read more
Source§

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

Source§

fn run(&mut self, world: &mut World, event: E)

Run this handler with the given event.
Source§

fn inputs_changed(&self, world: &World) -> bool

Returns true if any input resource was modified this sequence. Read more
Source§

fn name(&self) -> &'static str

Returns the handler’s name. Read more
Source§

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

Source§

fn run(&mut self, world: &mut World, event: E)

Run this handler with the given event.
Source§

fn inputs_changed(&self, world: &World) -> bool

Returns true if any input resource was modified this sequence. Read more
Source§

fn name(&self) -> &'static str

Returns the handler’s name. Read more
Source§

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

Source§

fn run(&mut self, world: &mut World, event: E)

Run this handler with the given event.
Source§

fn inputs_changed(&self, world: &World) -> bool

Returns true if any input resource was modified this sequence. Read more
Source§

fn name(&self) -> &'static str

Returns the handler’s name. Read more
Source§

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

Source§

fn run(&mut self, world: &mut World, event: E)

Run this handler with the given event.
Source§

fn inputs_changed(&self, world: &World) -> bool

Returns true if any input resource was modified this sequence. Read more
Source§

fn name(&self) -> &'static str

Returns the handler’s name. Read more
Source§

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

Source§

fn run(&mut self, world: &mut World, event: E)

Run this handler with the given event.
Source§

fn inputs_changed(&self, world: &World) -> bool

Returns true if any input resource was modified this sequence. Read more
Source§

fn name(&self) -> &'static str

Returns the handler’s name. Read more
Source§

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

Source§

fn run(&mut self, world: &mut World, event: E)

Run this handler with the given event.
Source§

fn inputs_changed(&self, world: &World) -> bool

Returns true if any input resource was modified this sequence. Read more
Source§

fn name(&self) -> &'static str

Returns the handler’s name. Read more
Source§

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

Source§

fn run(&mut self, world: &mut World, event: E)

Run this handler with the given event.
Source§

fn inputs_changed(&self, world: &World) -> bool

Returns true if any input resource was modified this sequence. Read more
Source§

fn name(&self) -> &'static str

Returns the handler’s name. Read more
Source§

impl<C: 'static, 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> Handler<E> for Callback<C, F, (P0, P1, P2, P3, P4, P5, P6, P7)>
where for<'a> &'a mut F: FnMut(&mut C, P0, P1, P2, P3, P4, P5, P6, P7, E) + FnMut(&mut C, 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§

fn run(&mut self, world: &mut World, event: E)

Run this handler with the given event.
Source§

fn inputs_changed(&self, world: &World) -> bool

Returns true if any input resource was modified this sequence. Read more
Source§

fn name(&self) -> &'static str

Returns the handler’s name. Read more

Auto Trait Implementations§

§

impl<C, F, Params> Freeze for Callback<C, F, Params>
where C: Freeze, F: Freeze, <Params as SystemParam>::State: Freeze,

§

impl<C, F, Params> RefUnwindSafe for Callback<C, F, Params>

§

impl<C, F, Params> Send for Callback<C, F, Params>
where C: Send, F: Send, <Params as SystemParam>::State: Send,

§

impl<C, F, Params> Sync for Callback<C, F, Params>
where C: Sync, F: Sync, <Params as SystemParam>::State: Sync,

§

impl<C, F, Params> Unpin for Callback<C, F, Params>
where C: Unpin, F: Unpin, <Params as SystemParam>::State: Unpin,

§

impl<C, F, Params> UnsafeUnpin for Callback<C, F, Params>
where C: UnsafeUnpin, F: UnsafeUnpin, <Params as SystemParam>::State: UnsafeUnpin,

§

impl<C, F, Params> UnwindSafe for Callback<C, F, Params>
where C: UnwindSafe, F: UnwindSafe, <Params as SystemParam>::State: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.