Skip to main content

jiff/error/tz/
db.rs

1use crate::error;
2
3#[derive(#[automatically_derived]impl ::core::clone::Clone for Error {
    #[inline]
    #[rustc_trivial_field_reads]
    fn clone(&self) -> Self {
        match self {
            Self::DisabledConcatenated => Error::DisabledConcatenated,
            Self::DisabledZoneInfo => Error::DisabledZoneInfo,
            Self::FailedTimeZone { name: __self_0 } =>
                Error::FailedTimeZone {
                    name: ::core::clone::Clone::clone(__self_0),
                },
            Self::FailedTimeZoneNoDatabaseConfigured { name: __self_0 } =>
                Error::FailedTimeZoneNoDatabaseConfigured {
                    name: ::core::clone::Clone::clone(__self_0),
                },
        }
    }
}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 {
            Self::DisabledConcatenated =>
                ::core::fmt::Formatter::write_str(f, "DisabledConcatenated"),
            Self::DisabledZoneInfo =>
                ::core::fmt::Formatter::write_str(f, "DisabledZoneInfo"),
            Self::FailedTimeZone { name: __self_0 } =>
                ::core::fmt::Formatter::debug_struct_field1_finish(f,
                    "FailedTimeZone name", &__self_0),
            Self::FailedTimeZoneNoDatabaseConfigured { name: __self_0 } =>
                ::core::fmt::Formatter::debug_struct_field1_finish(f,
                    "FailedTimeZoneNoDatabaseConfigured name", &__self_0),
        }
    }
}Debug)]
4#[cfg_attr(feature = "defmt", derive(defmt::Format))]
5pub(crate) enum Error {
6    #[cfg(feature = "tzdb-concatenated")]
7    ConcatenatedMissingIanaIdentifiers,
8    #[cfg(all(feature = "std", not(feature = "tzdb-concatenated")))]
9    DisabledConcatenated,
10    #[cfg(all(feature = "std", not(feature = "tzdb-zoneinfo")))]
11    DisabledZoneInfo,
12    FailedTimeZone {
13        #[cfg(feature = "alloc")]
14        #[cfg_attr(feature = "defmt", defmt(Debug2Format))]
15        name: alloc::boxed::Box<str>,
16    },
17    FailedTimeZoneNoDatabaseConfigured {
18        #[cfg(feature = "alloc")]
19        #[cfg_attr(feature = "defmt", defmt(Debug2Format))]
20        name: alloc::boxed::Box<str>,
21    },
22    #[cfg(feature = "tzdb-zoneinfo")]
23    ZoneInfoNoTzifFiles,
24    #[cfg(feature = "tzdb-zoneinfo")]
25    ZoneInfoStripPrefix,
26}
27
28impl Error {
29    pub(crate) fn failed_time_zone(_time_zone_name: &str) -> Error {
30        Error::FailedTimeZone {
31            #[cfg(feature = "alloc")]
32            name: _time_zone_name.into(),
33        }
34    }
35
36    pub(crate) fn failed_time_zone_no_database_configured(
37        _time_zone_name: &str,
38    ) -> Error {
39        Error::FailedTimeZoneNoDatabaseConfigured {
40            #[cfg(feature = "alloc")]
41            name: _time_zone_name.into(),
42        }
43    }
44}
45
46impl From<Error> for error::Error {
47    #[cold]
48    #[inline(never)]
49    fn from(err: Error) -> error::Error {
50        error::ErrorKind::TzDb(err).into()
51    }
52}
53
54impl error::IntoError for Error {
55    fn into_error(self) -> error::Error {
56        self.into()
57    }
58}
59
60impl core::fmt::Display for Error {
61    fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
62        use self::Error::*;
63
64        match *self {
65            #[cfg(feature = "tzdb-concatenated")]
66            ConcatenatedMissingIanaIdentifiers => f.write_str(
67                "found no IANA time zone identifiers in \
68                 concatenated tzdata file",
69            ),
70            #[cfg(all(feature = "std", not(feature = "tzdb-concatenated")))]
71            DisabledConcatenated => {
72                f.write_str("system concatenated tzdb unavailable")
73            }
74            #[cfg(all(feature = "std", not(feature = "tzdb-zoneinfo")))]
75            DisabledZoneInfo => {
76                f.write_str("system zoneinfo tzdb unavailable")
77            }
78            FailedTimeZone {
79                #[cfg(feature = "alloc")]
80                ref name,
81            } => {
82                #[cfg(feature = "alloc")]
83                {
84                    f.write_fmt(format_args!("failed to find time zone `{0}` in time zone database",
        name))write!(
85                        f,
86                        "failed to find time zone `{name}` \
87                         in time zone database",
88                    )
89                }
90                #[cfg(not(feature = "alloc"))]
91                {
92                    f.write_str(
93                        "failed to find time zone in time zone database",
94                    )
95                }
96            }
97            FailedTimeZoneNoDatabaseConfigured {
98                #[cfg(feature = "alloc")]
99                ref name,
100            } => {
101                #[cfg(feature = "std")]
102                {
103                    f.write_fmt(format_args!("failed to find time zone `{0}` since there is no time zone database configured",
        name))write!(
104                        f,
105                        "failed to find time zone `{name}` since there is no \
106                         time zone database configured",
107                    )
108                }
109                #[cfg(all(not(feature = "std"), feature = "alloc"))]
110                {
111                    write!(
112                        f,
113                        "failed to find time zone `{name}`, since there is no \
114                         global time zone database configured (and is \
115                         currently impossible to do so without Jiff's `std` \
116                         feature enabled, if you need this functionality, \
117                         please file an issue on Jiff's tracker with your \
118                         use case)",
119                    )
120                }
121                #[cfg(all(not(feature = "std"), not(feature = "alloc")))]
122                {
123                    f.write_str(
124                        "failed to find time zone, since there is no \
125                         global time zone database configured (and is \
126                         currently impossible to do so without Jiff's `std` \
127                         feature enabled, if you need this functionality, \
128                         please file an issue on Jiff's tracker with your \
129                         use case)",
130                    )
131                }
132            }
133            #[cfg(feature = "tzdb-zoneinfo")]
134            ZoneInfoNoTzifFiles => f.write_str(
135                "did not find any TZif files in zoneinfo time zone database",
136            ),
137            #[cfg(feature = "tzdb-zoneinfo")]
138            ZoneInfoStripPrefix => f.write_str(
139                "failed to strip zoneinfo time zone database directory \
140                 path from path to TZif file",
141            ),
142        }
143    }
144}