Skip to main content

Protocol

Trait Protocol 

Source
pub trait Protocol {
    type State;
    type Event;
    type Effect;

    // Required methods
    fn namespace(&self) -> &str;
    fn init(&self) -> Self::State;
    fn decode(&self, wire: Wire<'_>) -> Result<Self::Event, Reject>;
    fn step(
        &self,
        ctx: Ctx<'_, Self::State>,
        event: Self::Event,
    ) -> Transition<Self::State, Self::Effect>;
}
Expand description

A protocol: a namespace, an initial state, a decode boundary, and a state transition that is pure by contract.

  init   :              → S
  decode : Wire        ⇀ Event            (partial: may Reject)
  step   : (Ctx S, Event) → Transition (S, Effect)

decode is the single place raw bytes become a typed Event; a malformed/foreign message is an explicit Reject, not a silent no-op in step. step is then total over well-typed events and pure: no IO, no clocks, no globals. All side effects are described as values of the protocol’s own Effect type and performed by the extension’s Interpret shell.

Required Associated Types§

Source

type State

Protocol-private state, owned by the runtime and threaded through step.

Source

type Event

The protocol’s typed input, produced by decode.

Source

type Effect

The protocol’s own effect algebra (the core defines no global effect enum).

Required Methods§

Source

fn namespace(&self) -> &str

The namespace this protocol is registered and routed under.

Source

fn init(&self) -> Self::State

Initial state. init : 1 → S.

Source

fn decode(&self, wire: Wire<'_>) -> Result<Self::Event, Reject>

Decode the boundary into a typed event, or Reject it. decode : Wire ⇀ Event.

Source

fn step( &self, ctx: Ctx<'_, Self::State>, event: Self::Event, ) -> Transition<Self::State, Self::Effect>

Pure transition. step : (Ctx S, Event) → Transition (S, Effect).

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§