radnelac/common/
error.rs

1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
5use std::error::Error;
6use std::fmt;
7use std::fmt::Display;
8
9#[derive(Debug)]
10pub enum CalendarError {
11    InvalidYear,
12    InvalidMonth,
13    InvalidDay,
14    InvalidHour,
15    InvalidMinute,
16    InvalidSecond,
17    InvalidDayOfYear,
18    InvalidWeek,
19    DivisionByZero,
20    OutOfBounds,
21    MixedRadixWrongSize,
22    MixedRadixZeroBase,
23    EncounteredNaN,
24    ImpossibleResult,
25}
26
27impl Display for CalendarError {
28    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
29        match self {
30            CalendarError::InvalidYear => write!(f, "Invalid Year"),
31            CalendarError::InvalidMonth => write!(f, "Invalid Month"),
32            CalendarError::InvalidDay => write!(f, "Invalid Day"),
33            CalendarError::InvalidHour => write!(f, "Invalid Hour"),
34            CalendarError::InvalidMinute => write!(f, "Invalid Minute"),
35            CalendarError::InvalidSecond => write!(f, "Invalid Second"),
36            CalendarError::InvalidDayOfYear => write!(f, "Invalid day of year"),
37            CalendarError::InvalidWeek => write!(f, "Invalid week"),
38            CalendarError::DivisionByZero => write!(f, "Division By Zero"),
39            CalendarError::OutOfBounds => write!(f, "Out Of Bounds"),
40            CalendarError::MixedRadixWrongSize => write!(f, "Mixed radix slices have wrong size"),
41            CalendarError::MixedRadixZeroBase => write!(f, "Mixed radix base contains zero"),
42            CalendarError::EncounteredNaN => write!(f, "Encountered Not a Number (NaN)"),
43            CalendarError::ImpossibleResult => write!(f, "Impossible result"),
44        }
45    }
46}
47
48impl Error for CalendarError {}