pub struct Response<A, T> {
pub consumed: bool,
pub actions: Vec<A>,
pub timers: Vec<TimerCommand<T>>,
}Expand description
The result of a state machine transition.
A Response is a declarative description of what should happen:
which actions to emit, which timers to set or kill, and whether the
original event was consumed.
The state machine never executes side effects directly. The runtime
reads the Response and performs the actual timer operations and
action execution via dispatch.
§Three-field contract
| Field | Type | Meaning |
|---|---|---|
consumed | bool | true → caller must not forward the event further; false → caller should pass it to the next handler |
actions | Vec<A> | Ordered list of output actions to execute; may be empty |
timers | Vec<TimerCommand<T>> | Ordered timer instructions (set/kill); processed before actions by dispatch |
Build responses with the constructor methods (emit_one,
consume, pass_through) and the
chaining methods (with_timer,
with_kill_timer).
Fields§
§consumed: boolWhether the original event was consumed by the state machine.
true: the event was handled; the caller should not propagate it.false: the event was not handled; the caller should propagate it (e.g., pass through to the next hook in a chain).
actions: Vec<A>Actions to emit, in order.
May be empty if the transition only affects internal state or timers.
timers: Vec<TimerCommand<T>>Timer commands to execute, in order.
The runtime must process these commands after the actions.
A Set with an ID that already has an active
timer should reset (overwrite) that timer.
Implementations§
Source§impl<A, T> Response<A, T>
impl<A, T> Response<A, T>
Sourcepub const fn emit(actions: Vec<A>) -> Self
pub const fn emit(actions: Vec<A>) -> Self
Create a response that consumes the event and emits multiple actions.
Use this when a single transition produces two or more output actions that need to be dispatched together (e.g., a chord that generates a modifier keydown followed by a character keydown).
Sourcepub fn emit_one(action: A) -> Self
pub fn emit_one(action: A) -> Self
Create a response that consumes the event and emits a single action.
Use this for the common case where exactly one output action is produced (e.g., a confirmed debounce level, a recognized key stroke).
Sourcepub const fn consume() -> Self
pub const fn consume() -> Self
Create a response that consumes the event but emits no actions yet.
Use this when the state machine enters a pending (buffering) state
and will emit actions only on a later event or timeout — the
timer-pending pattern. Typically followed by
.with_timer(…) to start the decision window.
// Absorb the event and start a 50 ms window.
let r: Response<u8, ()> = Response::consume()
.with_timer((), Duration::from_millis(50));
r.assert_consumed();
r.assert_timer_set(());Sourcepub const fn pass_through() -> Self
pub const fn pass_through() -> Self
Create a response that does not consume the event.
Use this when this state machine does not handle the current event and the caller should pass it to the next handler in the chain (e.g., a key combination that is not part of this machine’s grammar).
Sourcepub fn with_timer(self, id: T, duration: Duration) -> Self
pub fn with_timer(self, id: T, duration: Duration) -> Self
Add a timer set command to this response.
This is a chainable builder method. It appends a
TimerCommand::Set with the given id and duration.
If a timer with the same ID is already running, the runtime
must reset it to the new duration.
Sourcepub fn with_kill_timer(self, id: T) -> Self
pub fn with_kill_timer(self, id: T) -> Self
Add a timer kill command to this response.
This is a chainable builder method. It appends a
TimerCommand::Kill for the given id. If no timer with
that ID is active, the runtime treats this as a no-op.
Source§impl<A: Debug, T: Copy + Eq + Debug> Response<A, T>
impl<A: Debug, T: Copy + Eq + Debug> Response<A, T>
Sourcepub fn assert_consumed(&self)
pub fn assert_consumed(&self)
Sourcepub fn assert_pass_through(&self)
pub fn assert_pass_through(&self)
Sourcepub fn assert_timer_set(&self, id: T)
pub fn assert_timer_set(&self, id: T)
Assert that a timer set command exists for the given ID.
§Panics
Panics if no Set command with the given ID is found.
Sourcepub fn assert_timer_kill(&self, id: T)
pub fn assert_timer_kill(&self, id: T)
Assert that a timer kill command exists for the given ID.
§Panics
Panics if no Kill command with the given ID is found.