Skip to main content

FanOut

Struct FanOut 

Source
pub struct FanOut<T>(pub T);
Expand description

Static fan-out combinator. Takes ownership of an event, borrows it, and dispatches &E to N handlers.

T is a tuple of handlers — construct via the fan_out! macro or directly: FanOut((a, b)). Macro-generated Handler<E> impls for tuple arities 2 through 8.

Each handler in the tuple must implement for<'e> Handler<&'e E>. To include an owned-event handler, wrap it in Cloned or Owned.

Zero allocation, concrete types — monomorphizes to direct calls. Boxes into Box<dyn Handler<E>> for type-erased storage.

For dynamic fan-out (runtime-determined handler count), use Broadcast.

§Examples

use nexus_rt::{WorldBuilder, ResMut, IntoHandler, Handler, FanOut, Cloned};

fn ref_handler(mut sink: ResMut<u64>, event: &u32) {
    *sink += *event as u64;
}

fn owned_handler(mut sink: ResMut<u64>, event: u32) {
    *sink += event as u64 * 10;
}

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

// Mix ref and owned handlers via Cloned adapter
let h1 = ref_handler.into_handler(world.registry());
let h2 = owned_handler.into_handler(world.registry());
let mut fan = FanOut((h1, Cloned(h2)));
fan.run(&mut world, 3u32);
assert_eq!(*world.resource::<u64>(), 33); // 3 + 30

Tuple Fields§

§0: T

Trait Implementations§

Source§

impl<E, H0, H1> Handler<E> for FanOut<(H0, H1)>
where H0: for<'e> Handler<&'e E> + Send, H1: for<'e> Handler<&'e E> + Send,

Source§

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

Run this handler with the given event.
Source§

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

Returns the handler’s name. Read more
Source§

impl<E, H0, H1, H2> Handler<E> for FanOut<(H0, H1, H2)>
where H0: for<'e> Handler<&'e E> + Send, H1: for<'e> Handler<&'e E> + Send, H2: for<'e> Handler<&'e E> + Send,

Source§

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

Run this handler with the given event.
Source§

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

Returns the handler’s name. Read more
Source§

impl<E, H0, H1, H2, H3> Handler<E> for FanOut<(H0, H1, H2, H3)>
where H0: for<'e> Handler<&'e E> + Send, H1: for<'e> Handler<&'e E> + Send, H2: for<'e> Handler<&'e E> + Send, H3: for<'e> Handler<&'e E> + Send,

Source§

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

Run this handler with the given event.
Source§

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

Returns the handler’s name. Read more
Source§

impl<E, H0, H1, H2, H3, H4> Handler<E> for FanOut<(H0, H1, H2, H3, H4)>
where H0: for<'e> Handler<&'e E> + Send, H1: for<'e> Handler<&'e E> + Send, H2: for<'e> Handler<&'e E> + Send, H3: for<'e> Handler<&'e E> + Send, H4: for<'e> Handler<&'e E> + Send,

Source§

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

Run this handler with the given event.
Source§

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

Returns the handler’s name. Read more
Source§

impl<E, H0, H1, H2, H3, H4, H5> Handler<E> for FanOut<(H0, H1, H2, H3, H4, H5)>
where H0: for<'e> Handler<&'e E> + Send, H1: for<'e> Handler<&'e E> + Send, H2: for<'e> Handler<&'e E> + Send, H3: for<'e> Handler<&'e E> + Send, H4: for<'e> Handler<&'e E> + Send, H5: for<'e> Handler<&'e E> + Send,

Source§

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

Run this handler with the given event.
Source§

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

Returns the handler’s name. Read more
Source§

impl<E, H0, H1, H2, H3, H4, H5, H6> Handler<E> for FanOut<(H0, H1, H2, H3, H4, H5, H6)>
where H0: for<'e> Handler<&'e E> + Send, H1: for<'e> Handler<&'e E> + Send, H2: for<'e> Handler<&'e E> + Send, H3: for<'e> Handler<&'e E> + Send, H4: for<'e> Handler<&'e E> + Send, H5: for<'e> Handler<&'e E> + Send, H6: for<'e> Handler<&'e E> + Send,

Source§

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

Run this handler with the given event.
Source§

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

Returns the handler’s name. Read more
Source§

impl<E, H0, H1, H2, H3, H4, H5, H6, H7> Handler<E> for FanOut<(H0, H1, H2, H3, H4, H5, H6, H7)>
where H0: for<'e> Handler<&'e E> + Send, H1: for<'e> Handler<&'e E> + Send, H2: for<'e> Handler<&'e E> + Send, H3: for<'e> Handler<&'e E> + Send, H4: for<'e> Handler<&'e E> + Send, H5: for<'e> Handler<&'e E> + Send, H6: for<'e> Handler<&'e E> + Send, H7: for<'e> Handler<&'e E> + Send,

Source§

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

Run this handler with the given event.
Source§

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

Returns the handler’s name. Read more

Auto Trait Implementations§

§

impl<T> Freeze for FanOut<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for FanOut<T>
where T: RefUnwindSafe,

§

impl<T> Send for FanOut<T>
where T: Send,

§

impl<T> Sync for FanOut<T>
where T: Sync,

§

impl<T> Unpin for FanOut<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for FanOut<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for FanOut<T>
where T: 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.