Skip to main content

noether_guard/
error.rs

1use std::fmt;
2
3/// Errors produced by noether-guard.
4#[derive(Debug, Clone)]
5pub enum Error {
6    /// No conservation laws registered.
7    NoLaws,
8    /// Value count mismatch on tick.
9    ValueCountMismatch { expected: usize, got: usize },
10    /// Invalid tolerance (must be >= 0).
11    InvalidTolerance(f64),
12    /// Invalid time step (must be >= 0).
13    InvalidTime(f64),
14}
15
16impl fmt::Display for Error {
17    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
18        match self {
19            Self::NoLaws => write!(f, "no conservation laws registered"),
20            Self::ValueCountMismatch { expected, got } => {
21                write!(f, "expected {expected} values, got {got}")
22            }
23            Self::InvalidTolerance(v) => write!(f, "invalid tolerance: {v}"),
24            Self::InvalidTime(v) => write!(f, "invalid time: {v}"),
25        }
26    }
27}
28
29impl std::error::Error for Error {}
30
31pub type Result<T> = std::result::Result<T, Error>;