Debian Codegraph @

debian/rust-vendor/jiff/src/error/zoned.rs

raw
1 use crate::{error, Unit};
2
3 #[derive(Clone, Debug)]
4 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
5 pub(crate) enum Error {
6 AddDateTime,
7 AddDays,
8 AddTimestamp,
9 ConvertDateTimeToTimestamp,
10 ConvertIntermediateDatetime,
11 FailedLengthOfDay,
12 FailedSpanNanoseconds,
13 FailedStartOfDay,
14 MismatchTimeZoneUntil { largest: Unit },
15 }
16
17 impl From<Error> for error::Error {
18 #[cold]
19 #[inline(never)]
20 fn from(err: Error) -> error::Error {
21 error::ErrorKind::Zoned(err).into()
22 }
23 }
24
25 impl error::IntoError for Error {
26 fn into_error(self) -> error::Error {
27 self.into()
28 }
29 }
30
31 impl core::fmt::Display for Error {
32 fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
33 use self::Error::*;
34
35 match *self {
36 AddDateTime => f.write_str(
37 "failed to add span to datetime from zoned datetime",
38 ),
39 AddDays => {
40 f.write_str("failed to add days to date in zoned datetime")
41 }
42 AddTimestamp => f.write_str(
43 "failed to add span to timestamp from zoned datetime",
44 ),
45 ConvertDateTimeToTimestamp => {
46 f.write_str("failed to convert civil datetime to timestamp")
47 }
48 ConvertIntermediateDatetime => f.write_str(
49 "failed to convert intermediate datetime \
50 to zoned timestamp",
51 ),
52 FailedLengthOfDay => f.write_str(
53 "failed to add 1 day to zoned datetime to find length of day",
54 ),
55 FailedSpanNanoseconds => f.write_str(
56 "failed to compute span in nanoseconds \
57 between zoned datetimes",
58 ),
59 FailedStartOfDay => {
60 f.write_str("failed to find start of day for zoned datetime")
61 }
62 MismatchTimeZoneUntil { largest } => write!(
63 f,
64 "computing the span between zoned datetimes, with \
65 {largest} units, requires that the time zones are \
66 equivalent, but the zoned datetimes have distinct \
67 time zones",
68 largest = largest.singular(),
69 ),
70 }
71 }
72 }