Skip to main content

Response

Struct Response 

Source
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

FieldTypeMeaning
consumedbooltrue → caller must not forward the event further; false → caller should pass it to the next handler
actionsVec<A>Ordered list of output actions to execute; may be empty
timersVec<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: bool

Whether 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>

Source

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

Source

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

Source

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(());
Source

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

Source

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.

Source

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>

Source

pub fn assert_consumed(&self)

Assert that the event was consumed.

§Panics

Panics if consumed is false.

Source

pub fn assert_pass_through(&self)

Assert that the event was not consumed (pass-through).

§Panics

Panics if consumed is true.

Source

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.

Source

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.

Source

pub fn assert_action_count(&self, expected: usize)

Assert the number of actions in the response.

§Panics

Panics if the action count does not match.

Trait Implementations§

Source§

impl<A: Clone, T: Clone> Clone for Response<A, T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<A: Debug, T: Debug> Debug for Response<A, T>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<A, T> Default for Response<A, T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<A: PartialEq, T: PartialEq> PartialEq for Response<A, T>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<A: Eq, T: Eq> Eq for Response<A, T>

Auto Trait Implementations§

§

impl<A, T> Freeze for Response<A, T>

§

impl<A, T> RefUnwindSafe for Response<A, T>

§

impl<A, T> Send for Response<A, T>
where A: Send, T: Send,

§

impl<A, T> Sync for Response<A, T>
where A: Sync, T: Sync,

§

impl<A, T> Unpin for Response<A, T>
where A: Unpin, T: Unpin,

§

impl<A, T> UnsafeUnpin for Response<A, T>

§

impl<A, T> UnwindSafe for Response<A, T>
where A: UnwindSafe, T: 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.