Struct Pure

pub struct Pure<L>(/* private fields */);
Expand description

EventHandler adapter over a PureLogic. Nothing persists, and the events compute_fields derives from a state change are prepended to the ones the logic emitted, so a derived event is processed before the children of the event that caused it.

Implementations§

§

impl<L> Pure<L>

pub fn new(logic: L) -> Pure<L>

pub fn logic(&self) -> &L

pub fn logic_mut(&mut self) -> &mut L

The logic this handler drives, so a caller can arm it between events.

Trait Implementations§

§

impl<L> Debug for Pure<L>
where L: Debug,

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl<E, S, L> EventHandler<E, S> for Pure<L>
where E: Event, S: State + Send + Sync, L: PureLogic<E, S> + Send + Sync,

§

type Context = ()

§

async fn create_context_for_batch( &self, _state: &S, ) -> Result<<Pure<L> as EventHandler<E, S>>::Context, Error>

§

async fn handle_event( &mut self, _ctx: &<Pure<L> as EventHandler<E, S>>::Context, event: &E, meta: EventMeta, prev_state: &S, state: S, ) -> Result<EventHandleResult<E, S>, Error>

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(...)).
§

fn compute_fields(&self, state: &mut S, prev_state: &S) -> Vec<E>

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.
§

fn collect_due_scheduled(&mut self, current_tick: u64) -> Vec<E>

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 — a clock the handler itself keeps — 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: &<Pure<L> as EventHandler<E, S>>::Context, _state: &mut S, ) -> Result<(), Error>

§

async fn persist_in_memory_state( &self, _ctx: &<Pure<L> as EventHandler<E, S>>::Context, _state: &S, ) -> Result<(), Error>

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

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, where an otherwise pure event still has to write because of what the state holds.
§

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

Whether ctx is a pure (DB-less) context that must be upgraded via upgrade_context before handling a full-context event.
§

fn upgrade_context( &self, ctx: Self::Context, _state: &S, ) -> impl Future<Output = Result<Self::Context, Error>> + Send
where Self::Context: Send,

Upgrade a pure context into a full one, carrying over all state accumulated so far. Only called when context_is_pure is true.

Auto Trait Implementations§

§

impl<L> Freeze for Pure<L>
where L: Freeze,

§

impl<L> RefUnwindSafe for Pure<L>
where L: RefUnwindSafe,

§

impl<L> Send for Pure<L>
where L: Send,

§

impl<L> Sync for Pure<L>
where L: Sync,

§

impl<L> Unpin for Pure<L>
where L: Unpin,

§

impl<L> UnwindSafe for Pure<L>
where L: 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.

§

impl<T> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
§

impl<T> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

§

impl<T> IntoRequest<T> for T

§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
§

impl<L> LayerExt<L> for L

§

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].
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,