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: HTrait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more