1use crate::error;
2
3#[derive(Clone, Debug)]
4#[cfg_attr(feature = "defmt", derive(defmt::Format))]
5pub(crate) enum Error {
6 FailedAddDays,
7 FailedAddDurationOverflowing,
8 FailedAddSpanDate,
9 FailedAddSpanOverflowing,
10 FailedAddSpanTime,
11 IllegalTimeWithMicrosecond,
12 IllegalTimeWithMillisecond,
13 IllegalTimeWithNanosecond,
14 OverflowDaysDuration,
15 OverflowTimeNanoseconds,
16}
17
18impl From<Error> for error::Error {
19 #[cold]
20 #[inline(never)]
21 fn from(err: Error) -> error::Error {
22 error::ErrorKind::Civil(err).into()
23 }
24}
25
26impl error::IntoError for Error {
27 fn into_error(self) -> error::Error {
28 self.into()
29 }
30}
31
32impl core::fmt::Display for Error {
33 fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
34 use self::Error::*;
35
36 match *self {
37 FailedAddDays => f.write_str("failed to add days to date"),
38 FailedAddDurationOverflowing => {
39 f.write_str("failed to add overflowing duration")
40 }
41 FailedAddSpanDate => f.write_str("failed to add span to date"),
42 FailedAddSpanOverflowing => {
43 f.write_str("failed to add overflowing span")
44 }
45 FailedAddSpanTime => f.write_str("failed to add span to time"),
46 IllegalTimeWithMicrosecond => f.write_str(
47 "cannot set both `TimeWith::microsecond` \
48 and `TimeWith::subsec_nanosecond`",
49 ),
50 IllegalTimeWithMillisecond => f.write_str(
51 "cannot set both `TimeWith::millisecond` \
52 and `TimeWith::subsec_nanosecond`",
53 ),
54 IllegalTimeWithNanosecond => f.write_str(
55 "cannot set both `TimeWith::nanosecond` \
56 and `TimeWith::subsec_nanosecond`",
57 ),
58 OverflowDaysDuration => f.write_str(
59 "number of days derived from duration exceed's \
60 Jiff's datetime limits",
61 ),
62 OverflowTimeNanoseconds => {
63 f.write_str("adding duration to time overflowed")
64 }
65 }
66 }
67}