Skip to main content

temporal_control/
error.rs

1//! Error model.
2
3use core::fmt;
4
5/// Reasons an algorithm could not produce a verdict.
6///
7/// An inconsistent network is not an error: it is a [`Verdict`](crate::Verdict) carrying an
8/// explanation. Errors mean the question was not answered.
9#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
10#[non_exhaustive]
11pub enum Error {
12    /// A time point does not belong to this network.
13    UnknownTimePoint,
14    /// A contingent link needs `0 < lo <= hi`.
15    InvalidContingentLink,
16    /// A checked arithmetic operation on [`Ticks`](crate::Ticks) or a size overflowed.
17    Overflow,
18    /// The step budget ran out before the algorithm finished.
19    BudgetExhausted,
20    /// The algorithm needs more matrix cells than [`Budget::max_cells`](crate::Budget::max_cells).
21    MemoryBudgetExceeded,
22    /// The allocator could not provide the memory the budget allowed.
23    OutOfMemory,
24    /// Two independent checks disagreed, or an internal invariant broke. This is a bug.
25    Internal,
26}
27
28impl fmt::Display for Error {
29    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30        let msg = match self {
31            Self::UnknownTimePoint => "time point does not belong to this network",
32            Self::InvalidContingentLink => "contingent link bounds must satisfy 0 < lo <= hi",
33            Self::Overflow => "tick arithmetic overflowed",
34            Self::BudgetExhausted => "step budget exhausted",
35            Self::MemoryBudgetExceeded => "memory budget exceeded",
36            Self::OutOfMemory => "allocation failed",
37            Self::Internal => "internal invariant violated",
38        };
39
40        f.write_str(msg)
41    }
42}
43
44impl core::error::Error for Error {}