Skip to main content

vihaco_stdlib/clock/
error.rs

1// SPDX-FileCopyrightText: 2026 The vihaco Authors
2// SPDX-License-Identifier: MIT
3
4/// Errors produced while validating or advancing a modeled clock.
5#[derive(Debug, PartialEq, Eq)]
6pub enum ClockFault {
7    ZeroTickRatio,
8    LocalCycleOverflow,
9    DurationOverflow,
10    GlobalTickOverflow,
11    SequenceOverflow,
12    SchedulingInPast,
13}
14
15impl std::fmt::Display for ClockFault {
16    fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
17        let message = match self {
18            Self::ZeroTickRatio => "global ticks per local cycle must be nonzero",
19            Self::LocalCycleOverflow => "local cycle arithmetic overflowed",
20            Self::DurationOverflow => "global duration arithmetic overflowed",
21            Self::GlobalTickOverflow => "global tick arithmetic overflowed",
22            Self::SequenceOverflow => "global clock sequence overflowed",
23            Self::SchedulingInPast => "cannot schedule an event in the past",
24        };
25        formatter.write_str(message)
26    }
27}
28
29impl std::error::Error for ClockFault {}