Skip to main content

vihaco_stdlib/clock/
traits.rs

1// SPDX-FileCopyrightText: 2026 The vihaco Authors
2// SPDX-License-Identifier: MIT
3
4use super::{GlobalTick, GlobalTicksPerLocalCycle, Schedule};
5
6/// Runtime instructions provide the local duration of their operation.
7pub trait TimedInstruction {
8    fn local_cycles(&self) -> super::LocalCycles;
9}
10
11/// Generic boundary for a component that participates in a global event loop.
12pub trait ClockedComponent: Sized {
13    type Event;
14    type Completion;
15    type Fault;
16
17    fn step_at(
18        &mut self,
19        global_tick: GlobalTick,
20        ticks_per_local_cycle: GlobalTicksPerLocalCycle,
21    ) -> Result<Option<Schedule<Self::Event>>, Self::Fault>;
22
23    fn resume(
24        &mut self,
25        completion: Self::Completion,
26        global_tick: GlobalTick,
27        ticks_per_local_cycle: GlobalTicksPerLocalCycle,
28    ) -> Result<Option<Schedule<Self::Event>>, Self::Fault>;
29
30    fn next_boundary_at(
31        &self,
32        global_tick: GlobalTick,
33        ticks_per_local_cycle: GlobalTicksPerLocalCycle,
34    ) -> Result<GlobalTick, Self::Fault>;
35}