vihaco_runtime/dispatch.rs
1// SPDX-FileCopyrightText: 2026 The vihaco Authors
2// SPDX-License-Identifier: MIT
3
4use crate::Composite;
5
6/// Dispatch a composite instruction to its destination's [`crate::Step`].
7///
8/// Available with the experimental `typed-declarations` feature. Implementations
9/// select a field route and leaf instruction type from the aggregate instruction
10/// and forward the shared context to its authored Step. `Context` defaults to `()`.
11pub trait Dispatch<Context: ?Sized = ()>: Composite {
12 /// The aggregate instruction type accepted by this composite.
13 type Instruction;
14
15 /// Select and run the step, borrowing the instruction without consuming it.
16 ///
17 /// # Errors
18 ///
19 /// Returns the selected step's error unchanged. State changes and effects
20 /// already applied by the step are not rolled back; recovery or termination
21 /// is the caller's responsibility.
22 fn dispatch(&mut self, instruction: &Self::Instruction, context: &Context) -> eyre::Result<()>;
23}