Skip to main content

Cloned

Struct Cloned 

Source
pub struct Cloned<H>(pub H);
Expand description

Reference-to-owned adapter. Wraps a Handler<E> and implements Handler<&E> — the event is cloned before dispatch.

Explicit opt-in to the clone cost. For E: Copy the compiler elides the clone entirely.

Use when an owned-event handler needs to participate in a reference-based dispatch context (e.g. inside a FanOut).

§Examples

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

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

fn process(mut counter: ResMut<Counter>, event: u32) {
    counter.0 += event as u64;
}

let mut builder = WorldBuilder::new();
builder.register(Counter(0));
let mut world = builder.build();

let h = process.into_handler(world.registry());
let mut adapted = Cloned(h);
adapted.run(&mut world, &5u32);
assert_eq!(world.resource::<Counter>().0, 5);

Tuple Fields§

§0: H

Trait Implementations§

Source§

impl<'e, E: Clone + 'e, H: Handler<E> + Send> Handler<&'e E> for Cloned<H>

Source§

fn run(&mut self, world: &mut World, event: &'e 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<H> Freeze for Cloned<H>
where H: Freeze,

§

impl<H> RefUnwindSafe for Cloned<H>
where H: RefUnwindSafe,

§

impl<H> Send for Cloned<H>
where H: Send,

§

impl<H> Sync for Cloned<H>
where H: Sync,

§

impl<H> Unpin for Cloned<H>
where H: Unpin,

§

impl<H> UnsafeUnpin for Cloned<H>
where H: UnsafeUnpin,

§

impl<H> UnwindSafe for Cloned<H>
where H: 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<E, H> IntoHandler<E, Resolved> for H
where H: Handler<E> + 'static,

Source§

type Handler = H

The concrete handler type produced.
Source§

fn into_handler(self, _registry: &Registry) -> H

Convert this function into a handler, resolving parameters from the registry.
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.