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§
Required Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".