pub struct PureEventHandler { /* private fields */ }Expand description
DB-free handler over the pure game logic. Routes every event to
OverlordLogic; used by tests and simulations through the synchronous
System::run.
Implementations§
Source§impl PureEventHandler
impl PureEventHandler
pub fn new(logic: OverlordLogic) -> Self
Trait Implementations§
Source§impl EventHandler<OverlordEvent, OverlordState> for PureEventHandler
impl EventHandler<OverlordEvent, OverlordState> for PureEventHandler
type Context = ()
async fn create_context_for_batch( &self, _state: &OverlordState, ) -> Result<Self::Context>
Source§async fn handle_event(
&mut self,
_ctx: &Self::Context,
event: &OverlordEvent,
meta: EventMeta,
prev_state: &OverlordState,
state: OverlordState,
) -> Result<EventHandleResult<OverlordEvent, OverlordState>>
async fn handle_event( &mut self, _ctx: &Self::Context, event: &OverlordEvent, meta: EventMeta, prev_state: &OverlordState, state: OverlordState, ) -> Result<EventHandleResult<OverlordEvent, OverlordState>>
One call per event.
prev_state is the System’s state before this event
(same data as state, by reference — avoids an extra clone for the
compute_fields diff). Impls are responsible for:
pure state mutation -> compute_fields fold (diff vs prev_state, runs for
failed results too; prepend emitted events) -> DB persistence /
validation -> analytics deferral.
Err(_) aborts the whole batch (txn rollback). “Soft” failures must be
returned as Ok(EventHandleResult::fail(...)).Source§fn compute_fields(
&self,
state: &mut OverlordState,
prev_state: &OverlordState,
) -> Vec<OverlordEvent>
fn compute_fields( &self, state: &mut OverlordState, prev_state: &OverlordState, ) -> Vec<OverlordEvent>
Can be used to compute fields that arent stored in database, but computed from stored data.
Also can emit events on some logical data changes. This events eventually can change state.
Sync, no DB. Called by impls inside
handle_event and by
System::apply_state_with_compute_fields.Source§fn collect_due_scheduled(&mut self, current_tick: u64) -> Vec<OverlordEvent>
fn collect_due_scheduled(&mut self, current_tick: u64) -> Vec<OverlordEvent>
Events the handler scheduled internally that are due at
current_tick.
Drained alongside the delayed/cron plugins on every tick. Lets a
handler own domain scheduling (e.g. the fight clock) so the same
state drives both the live system and standalone simulations.
Deliberately has no default body — every impl must state it explicitly.async fn finalize_state( &self, _ctx: &Self::Context, _state: &mut OverlordState, ) -> Result<()>
Source§async fn persist_in_memory_state(
&self,
_ctx: &Self::Context,
_state: &OverlordState,
) -> Result<()>
async fn persist_in_memory_state( &self, _ctx: &Self::Context, _state: &OverlordState, ) -> Result<()>
Persist in-memory state to DB context before commit.
Called by flush_state to save changes accumulated between batches.
§fn event_needs_full_context(&self, _event: &E, _state: &S) -> bool
fn event_needs_full_context(&self, _event: &E, _state: &S) -> bool
Whether handling
event may touch the context’s backing resources
(DB transaction, persistence). Handlers that support pure (DB-less)
contexts override this for events whose handling is pure logic
end-to-end; the default — true for every event — keeps the eager
full-context behavior. state is the System state at dispatch time —
handlers use it for state-dependent persistence (e.g. quest
subscriptions that persist progress on otherwise-pure events).§fn create_pure_context_for_batch(
&self,
state: &S,
) -> impl Future<Output = Result<Self::Context, Error>> + Send
fn create_pure_context_for_batch( &self, state: &S, ) -> impl Future<Output = Result<Self::Context, Error>> + Send
Create a context for a batch whose events all have
event_needs_full_context == false. Defaults to the full context.§fn context_is_pure(&self, _ctx: &Self::Context) -> bool
fn context_is_pure(&self, _ctx: &Self::Context) -> bool
Whether
ctx is a pure (DB-less) context that must be upgraded via
upgrade_context before handling a full-context event.Auto Trait Implementations§
impl Freeze for PureEventHandler
impl !RefUnwindSafe for PureEventHandler
impl Send for PureEventHandler
impl Sync for PureEventHandler
impl Unpin for PureEventHandler
impl !UnwindSafe for PureEventHandler
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
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Applies the layer to a service and wraps it in [
Layered].