Skip to main content

deep_time/
error.rs

1//! [`DtErrKind`] and main error type [`DtErr`].
2//! [`DtErr`] is a type alias to [`AnErr`].
3
4use crate::AnErr;
5
6/// The kind of error returned by deep-time.
7///
8/// Almost every function in this crate that can fail returns a
9/// [`DtErr`](type.DtErr.html). That error is made of two parts:
10///
11/// 1. A **kind** — one of the variants of this enum (what went wrong).
12/// 2. A short **reason** string — optional extra detail (up to 15 bytes).
13///
14/// Those two pieces live inside [`AnErr`](struct.AnErr.html). [`DtErr`](type.DtErr.html)
15/// is simply `AnErr<DtErrKind, 15>` — the whole error is 16 bytes.
16///
17/// Create one with the [`an_err!`](macro.an_err!.html) macro, and read the kind
18/// back with [`.kind()`](struct.AnErr.html#method.kind):
19///
20/// ```
21/// use deep_time::{DtErr, DtErrKind, an_err};
22///
23/// let err: DtErr = an_err!(DtErrKind::YearOutOfRange, "year={}", 10_000);
24/// assert_eq!(err.kind(), DtErrKind::YearOutOfRange);
25/// ```
26///
27/// When printed, an error looks like `YearOutOfRange` or
28/// `YearOutOfRange: year=10000`.
29///
30/// This enum is marked `#[non_exhaustive]`, so new variants may be added in
31/// later releases. Always keep a catch-all arm (`_ => ...`) when matching.
32#[non_exhaustive]
33#[repr(u8)]
34#[derive(Debug, Clone, Copy, PartialEq, Eq)]
35#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
36#[cfg_attr(feature = "tsify", derive(tsify::Tsify))]
37#[cfg_attr(feature = "defmt", derive(defmt::Format))]
38pub enum DtErrKind {
39    UnexpectedEnd,
40    TruncatedDirective,
41    UnknownItem,
42    MissingFeature,
43    MissingRefTimeOrStd,
44    MustStartWith,
45    UnsupportedItem,
46    MismatchedLiteral,
47    ExpectedUnit,
48    ExpectedValue,
49    ExpectedYear,
50    ExpectedCentury,
51    ExpectedMonth,
52    ExpectedDay,
53    ExpectedDayOfYear,
54    ExpectedHour,
55    ExpectedMinute,
56    ExpectedSecond,
57    ExpectedFractional,
58    ExpectedTimestamp,
59    ExpectedWeekNumber,
60    ExpectedWeekdayNumber,
61    ExpectedDigits,
62    ExpectedMonWeekday,
63    ExpectedSunWeekday,
64    ExpectedMonWeek,
65    ExpectedSunWeek,
66    MonWeekdayOutOfRange,
67    SunWeekdayOutOfRange,
68    InvalidCodeId,
69    NonMonotonic,
70    TFieldTooShort,
71    PFieldTooShort,
72    InvalidSubmillisecond,
73    InvalidWeekdayName,
74    InvalidMonthName,
75    InvalidMeridiem,
76    InvalidScale,
77    InvalidDate,
78    InvalidTime,
79    InvalidYear,
80    InvalidMonth,
81    InvalidDay,
82    InvalidDayOfYear,
83    InvalidIsoWeekYear,
84    InvalidIsoWeek,
85    InvalidSunWeek,
86    InvalidMonWeek,
87    InvalidHour,
88    InvalidMinute,
89    InvalidSecond,
90    InvalidFractional,
91    InvalidTimestamp,
92    InvalidName,
93    InvalidTimeZone,
94    OffsetMissingSign,
95    InvalidOffsetHour,
96    InvalidOffsetMinute,
97    InvalidOffsetSecond,
98    InvalidOffsetColons,
99    InvalidOffset,
100    InvalidNumber,
101    InvalidItem,
102    InvalidBytes,
103    InvalidSyntax,
104    OutOfRange,
105    MonthOutOfRange,
106    DayOutOfRange,
107    DayOfYearOutOfRange,
108    HourOutOfRange,
109    MinuteOutOfRange,
110    SecondOutOfRange,
111    WeekOutOfRange,
112    IsoWeekOutOfRange,
113    YearOutOfRange,
114    FracOutOfRange,
115    MjdOutOfRange,
116    TrailingCharacters,
117    Incomplete,
118    InvalidInput,
119    InvalidLen,
120    InternalErr,
121    ConversionFail,
122    IOErr,
123    Empty,
124}
125
126/// Wrapper around [`AnErr`].
127///
128/// A [`DtErr`] object is 16 bytes.
129pub type DtErr = AnErr<DtErrKind, 15>;