pub struct Adapt<F, H> { /* private fields */ }Expand description
Lightweight adapter that decodes a wire-format event into a domain type before dispatching to an inner handler.
Implements Handler<Wire> by calling decode(Wire) -> Option<T>,
then forwarding T to the inner Handler<T>. Skips dispatch when
decode returns None (wrong template, decode error, filtered, etc.).
The decode function takes Wire by value. For reference types like
SBE flyweight decoders (ReadBuf<'a>), this is already a borrow -
no double indirection.
Both the decode function and inner handler are concrete types — monomorphizes to a direct call chain with no vtable overhead.
§Examples
use nexus_rt::{WorldBuilder, ResMut, IntoHandler, Handler};
use nexus_rt::Adapt;
// Wire event — in practice this would be a decoder/buffer type.
struct WireMsg(u32);
// Decode takes Wire by value. For reference-type wire events
// (e.g. SBE flyweight decoders like MessageHeaderDecoder<ReadBuf<'a>>),
// this is already a borrow — no double indirection.
fn decode_wire(wire: &WireMsg) -> Option<u64> {
Some(wire.0 as u64)
}
fn accumulate(mut counter: ResMut<u64>, event: u64) {
*counter += event;
}
let mut builder = WorldBuilder::new();
builder.register::<u64>(0);
let mut world = builder.build();
let handler = accumulate.into_handler(world.registry());
let mut adapted: Adapt<_, _> = Adapt::new(decode_wire, handler);
// Wire type is &WireMsg — reference type taken by value.
adapted.run(&mut world, &WireMsg(10));
adapted.run(&mut world, &WireMsg(5));
assert_eq!(*world.resource::<u64>(), 15);Implementations§
Trait Implementations§
Auto Trait Implementations§
impl<F, H> Freeze for Adapt<F, H>
impl<F, H> RefUnwindSafe for Adapt<F, H>where
F: RefUnwindSafe,
H: RefUnwindSafe,
impl<F, H> Send for Adapt<F, H>
impl<F, H> Sync for Adapt<F, H>
impl<F, H> Unpin for Adapt<F, H>
impl<F, H> UnsafeUnpin for Adapt<F, H>where
F: UnsafeUnpin,
H: UnsafeUnpin,
impl<F, H> UnwindSafe for Adapt<F, H>where
F: UnwindSafe,
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