Skip to main content

jiff/error/tz/
timezone.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::ConvertNonFixed { kind: __self_0 } =>
                Error::ConvertNonFixed {
                    kind: ::core::clone::Clone::clone(__self_0),
                },
            Self::FailedSystem => Error::FailedSystem,
        }
    }
}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::ConvertNonFixed { kind: __self_0 } =>
                ::core::fmt::Formatter::debug_struct_field1_finish(f,
                    "ConvertNonFixed kind", &__self_0),
            Self::FailedSystem =>
                ::core::fmt::Formatter::write_str(f, "FailedSystem"),
        }
    }
}Debug)]
4#[cfg_attr(feature = "defmt", derive(defmt::Format))]
5pub(crate) enum Error {
6    ConvertNonFixed {
7        kind: &'static str,
8    },
9    #[cfg(not(feature = "tz-system"))]
10    FailedSystem,
11}
12
13impl From<Error> for error::Error {
14    #[cold]
15    #[inline(never)]
16    fn from(err: Error) -> error::Error {
17        error::ErrorKind::TzTimeZone(err).into()
18    }
19}
20
21impl error::IntoError for Error {
22    fn into_error(self) -> error::Error {
23        self.into()
24    }
25}
26
27impl core::fmt::Display for Error {
28    fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
29        use self::Error::*;
30
31        match *self {
32            ConvertNonFixed { kind } => f.write_fmt(format_args!("cannot convert non-fixed {0} time zone to offset without a timestamp or civil datetime",
        kind))write!(
33                f,
34                "cannot convert non-fixed {kind} time zone to offset \
35                 without a timestamp or civil datetime",
36            ),
37            #[cfg(not(feature = "tz-system"))]
38            FailedSystem => f.write_str("failed to get system time zone"),
39        }
40    }
41}