Skip to main content

jiff/error/tz/
system.rs

1#[cfg(not(feature = "tz-system"))]
2pub(crate) use self::disabled::*;
3#[cfg(feature = "tz-system")]
4pub(crate) use self::enabled::*;
5
6#[cfg(not(feature = "tz-system"))]
7mod disabled {
8    #[derive(#[automatically_derived]impl ::core::clone::Clone for Error {
    #[inline]
    #[rustc_trivial_field_reads]
    fn clone(&self) -> Self { match *self {} }
}Clone, #[automatically_derived]impl ::core::fmt::Debug for Error {
    #[inline]
    #[rustc_trivial_field_reads]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match *self {}
    }
}Debug)]
9    #[cfg_attr(feature = "defmt", derive(defmt::Format))]
10    pub(crate) enum Error {}
11
12    impl core::fmt::Display for Error {
13        fn fmt(&self, _: &mut core::fmt::Formatter) -> core::fmt::Result {
14            ::core::panicking::unreachable_default_msg()unreachable!()
15        }
16    }
17}
18
19#[cfg(feature = "tz-system")]
20mod enabled {
21    use crate::error;
22
23    #[derive(Clone, Debug)]
24    #[cfg_attr(feature = "defmt", derive(defmt::Format))]
25    pub(crate) enum Error {
26        FailedEnvTz,
27        FailedEnvTzAsTzif,
28        FailedPosixTzAndUtf8,
29        FailedSystemTimeZone,
30        FailedUnnamedTzifInvalid,
31        FailedUnnamedTzifRead,
32        #[cfg(windows)]
33        WindowsMissingIanaMapping,
34        #[cfg(windows)]
35        WindowsTimeZoneKeyName,
36        #[cfg(windows)]
37        WindowsUtf16DecodeInvalid,
38        #[cfg(windows)]
39        WindowsUtf16DecodeNul,
40    }
41
42    impl From<Error> for error::Error {
43        #[cold]
44        #[inline(never)]
45        fn from(err: Error) -> error::Error {
46            error::ErrorKind::TzSystem(err).into()
47        }
48    }
49
50    impl error::IntoError for Error {
51        fn into_error(self) -> error::Error {
52            self.into()
53        }
54    }
55
56    impl core::fmt::Display for Error {
57        fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
58            use self::Error::*;
59
60            match *self {
61                FailedEnvTz => f.write_str(
62                    "`TZ` environment variable set, but failed to read value",
63                ),
64                FailedEnvTzAsTzif => f.write_str(
65                    "failed to read `TZ` environment variable value \
66                     as a TZif file after attempting (and failing) a tzdb \
67                     lookup for that same value",
68                ),
69                FailedPosixTzAndUtf8 => f.write_str(
70                    "failed to parse `TZ` environment variable as either \
71                     a POSIX time zone transition string or as valid UTF-8",
72                ),
73                FailedSystemTimeZone => {
74                    f.write_str("failed to find system time zone")
75                }
76                FailedUnnamedTzifInvalid => f.write_str(
77                    "found invalid TZif data in unnamed time zone file",
78                ),
79                FailedUnnamedTzifRead => f.write_str(
80                    "failed to read TZif data from unnamed time zone file",
81                ),
82                #[cfg(windows)]
83                WindowsMissingIanaMapping => f.write_str(
84                    "found Windows time zone name, \
85                     but could not find a mapping for it to an \
86                     IANA time zone name",
87                ),
88                #[cfg(windows)]
89                WindowsTimeZoneKeyName => f.write_str(
90                    "could not get `TimeZoneKeyName` from \
91                     winapi `DYNAMIC_TIME_ZONE_INFORMATION`",
92                ),
93                #[cfg(windows)]
94                WindowsUtf16DecodeInvalid => f.write_str(
95                    "failed to convert `u16` slice to UTF-8 \
96                     (invalid UTF-16)",
97                ),
98                #[cfg(windows)]
99                WindowsUtf16DecodeNul => f.write_str(
100                    "failed to convert `u16` slice to UTF-8 \
101                     (no NUL terminator found)",
102                ),
103            }
104        }
105    }
106}