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