Skip to main content

use_geode/
error.rs

1use core::fmt;
2use std::error::Error;
3
4/// Errors returned by checked Geode helpers.
5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6pub enum GeodeError {
7    /// Type vectors must contain at least one component.
8    EmptyTypeVector,
9    /// A requested component index was not present in the type vector.
10    IndexOutOfBounds,
11    /// A checked arithmetic operation overflowed `u64` or `u128`.
12    ArithmeticOverflow,
13    /// An exact division request had a zero divisor or non-zero remainder.
14    DivisionNotExact,
15    /// Input values violated a crate invariant.
16    InvalidInput,
17}
18
19impl fmt::Display for GeodeError {
20    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
21        match self {
22            Self::EmptyTypeVector => {
23                formatter.write_str("type vectors must contain at least one component")
24            },
25            Self::IndexOutOfBounds => formatter.write_str("type vector index is out of bounds"),
26            Self::ArithmeticOverflow => {
27                formatter.write_str("geode arithmetic overflowed its exact integer representation")
28            },
29            Self::DivisionNotExact => formatter.write_str("geode division was not exact"),
30            Self::InvalidInput => formatter.write_str("geode input violated a crate invariant"),
31        }
32    }
33}
34
35impl Error for GeodeError {}