vihaco_runtime/step.rs
1// SPDX-FileCopyrightText: 2026 The vihaco Authors
2// SPDX-License-Identifier: MIT
3
4use crate::{Composite, Execute, Field};
5
6/// Execution behavior for one composite field route and instruction type.
7///
8/// Available with the experimental `typed-declarations` feature. Use
9/// [`crate::field!`] to select a direct field or a nested route. The final child
10/// must implement [`Execute<I>`], while the step implementation supplies the
11/// composite's behavior, including runtime input and effect handling.
12/// [`crate::BuildMessage`] is an optional helper for preparing that input; it
13/// does not provide a step automatically. `Context` is shared execution input,
14/// defaults to `()`, and is forwarded by dispatch; the Step decides how to use it.
15/// With `program-image-execution`, a composite with a `#[program]` execution-state device
16/// supplies operand storage. Steps remain authored; program execution handles
17/// running checks and PC progression outside this trait.
18pub trait Step<F, I, Context: ?Sized = ()>
19where
20 Self: Composite + Field<F>,
21 <Self as Field<F>>::Child: Execute<I>,
22{
23 /// Perform a step for the selected destination, borrowing its instruction.
24 ///
25 /// # Errors
26 ///
27 /// Returns failures from preparing runtime input, executing the instruction,
28 /// or handling its effects. Implementations can use `?` to convert compatible
29 /// execution errors into [`eyre::Report`], including `Infallible`, or to
30 /// propagate existing reports unchanged. Returning an error does not roll
31 /// back state changes or effects already applied.
32 fn step(&mut self, instruction: &I, context: &Context) -> eyre::Result<()>;
33}