Skip to main content

jiff/error/fmt/
rfc9557.rs

1use crate::{error, util::escape};
2
3#[derive(#[automatically_derived]impl ::core::clone::Clone for Error {
    #[inline]
    #[rustc_trivial_field_reads]
    fn clone(&self) -> Self {
        match self {
            Self::EndOfInputAnnotation => Error::EndOfInputAnnotation,
            Self::EndOfInputAnnotationClose =>
                Error::EndOfInputAnnotationClose,
            Self::EndOfInputAnnotationKey => Error::EndOfInputAnnotationKey,
            Self::EndOfInputAnnotationSeparator =>
                Error::EndOfInputAnnotationSeparator,
            Self::EndOfInputAnnotationValue =>
                Error::EndOfInputAnnotationValue,
            Self::EndOfInputTzAnnotationClose =>
                Error::EndOfInputTzAnnotationClose,
            Self::UnexpectedByteAnnotation { byte: __self_0 } =>
                Error::UnexpectedByteAnnotation {
                    byte: ::core::clone::Clone::clone(__self_0),
                },
            Self::UnexpectedByteAnnotationClose { byte: __self_0 } =>
                Error::UnexpectedByteAnnotationClose {
                    byte: ::core::clone::Clone::clone(__self_0),
                },
            Self::UnexpectedByteAnnotationKey { byte: __self_0 } =>
                Error::UnexpectedByteAnnotationKey {
                    byte: ::core::clone::Clone::clone(__self_0),
                },
            Self::UnexpectedByteAnnotationValue { byte: __self_0 } =>
                Error::UnexpectedByteAnnotationValue {
                    byte: ::core::clone::Clone::clone(__self_0),
                },
            Self::UnexpectedByteAnnotationSeparator { byte: __self_0 } =>
                Error::UnexpectedByteAnnotationSeparator {
                    byte: ::core::clone::Clone::clone(__self_0),
                },
            Self::UnexpectedByteTzAnnotationClose { byte: __self_0 } =>
                Error::UnexpectedByteTzAnnotationClose {
                    byte: ::core::clone::Clone::clone(__self_0),
                },
            Self::UnexpectedSlashAnnotationSeparator =>
                Error::UnexpectedSlashAnnotationSeparator,
            Self::UnsupportedAnnotationCritical =>
                Error::UnsupportedAnnotationCritical,
        }
    }
}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::EndOfInputAnnotation =>
                ::core::fmt::Formatter::write_str(f, "EndOfInputAnnotation"),
            Self::EndOfInputAnnotationClose =>
                ::core::fmt::Formatter::write_str(f,
                    "EndOfInputAnnotationClose"),
            Self::EndOfInputAnnotationKey =>
                ::core::fmt::Formatter::write_str(f,
                    "EndOfInputAnnotationKey"),
            Self::EndOfInputAnnotationSeparator =>
                ::core::fmt::Formatter::write_str(f,
                    "EndOfInputAnnotationSeparator"),
            Self::EndOfInputAnnotationValue =>
                ::core::fmt::Formatter::write_str(f,
                    "EndOfInputAnnotationValue"),
            Self::EndOfInputTzAnnotationClose =>
                ::core::fmt::Formatter::write_str(f,
                    "EndOfInputTzAnnotationClose"),
            Self::UnexpectedByteAnnotation { byte: __self_0 } =>
                ::core::fmt::Formatter::debug_struct_field1_finish(f,
                    "UnexpectedByteAnnotation byte", &__self_0),
            Self::UnexpectedByteAnnotationClose { byte: __self_0 } =>
                ::core::fmt::Formatter::debug_struct_field1_finish(f,
                    "UnexpectedByteAnnotationClose byte", &__self_0),
            Self::UnexpectedByteAnnotationKey { byte: __self_0 } =>
                ::core::fmt::Formatter::debug_struct_field1_finish(f,
                    "UnexpectedByteAnnotationKey byte", &__self_0),
            Self::UnexpectedByteAnnotationValue { byte: __self_0 } =>
                ::core::fmt::Formatter::debug_struct_field1_finish(f,
                    "UnexpectedByteAnnotationValue byte", &__self_0),
            Self::UnexpectedByteAnnotationSeparator { byte: __self_0 } =>
                ::core::fmt::Formatter::debug_struct_field1_finish(f,
                    "UnexpectedByteAnnotationSeparator byte", &__self_0),
            Self::UnexpectedByteTzAnnotationClose { byte: __self_0 } =>
                ::core::fmt::Formatter::debug_struct_field1_finish(f,
                    "UnexpectedByteTzAnnotationClose byte", &__self_0),
            Self::UnexpectedSlashAnnotationSeparator =>
                ::core::fmt::Formatter::write_str(f,
                    "UnexpectedSlashAnnotationSeparator"),
            Self::UnsupportedAnnotationCritical =>
                ::core::fmt::Formatter::write_str(f,
                    "UnsupportedAnnotationCritical"),
        }
    }
}Debug)]
4#[cfg_attr(feature = "defmt", derive(defmt::Format))]
5pub(crate) enum Error {
6    EndOfInputAnnotation,
7    EndOfInputAnnotationClose,
8    EndOfInputAnnotationKey,
9    EndOfInputAnnotationSeparator,
10    EndOfInputAnnotationValue,
11    EndOfInputTzAnnotationClose,
12    UnexpectedByteAnnotation { byte: u8 },
13    UnexpectedByteAnnotationClose { byte: u8 },
14    UnexpectedByteAnnotationKey { byte: u8 },
15    UnexpectedByteAnnotationValue { byte: u8 },
16    UnexpectedByteAnnotationSeparator { byte: u8 },
17    UnexpectedByteTzAnnotationClose { byte: u8 },
18    UnexpectedSlashAnnotationSeparator,
19    UnsupportedAnnotationCritical,
20}
21
22impl error::IntoError for Error {
23    fn into_error(self) -> error::Error {
24        self.into()
25    }
26}
27
28impl From<Error> for error::Error {
29    #[cold]
30    #[inline(never)]
31    fn from(err: Error) -> error::Error {
32        error::ErrorKind::FmtRfc9557(err).into()
33    }
34}
35
36impl core::fmt::Display for Error {
37    fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
38        use self::Error::*;
39
40        match *self {
41            EndOfInputAnnotation => f.write_str(
42                "expected the start of an RFC 9557 annotation or IANA \
43                 time zone component name, but found end of input instead",
44            ),
45            EndOfInputAnnotationClose => f.write_str(
46                "expected an `]` after parsing an RFC 9557 annotation key \
47                 and value, but found end of input instead",
48            ),
49            EndOfInputAnnotationKey => f.write_str(
50                "expected the start of an RFC 9557 annotation key, \
51                 but found end of input instead",
52            ),
53            EndOfInputAnnotationSeparator => f.write_str(
54                "expected an `=` after parsing an RFC 9557 annotation key, \
55                 but found end of input instead",
56            ),
57            EndOfInputAnnotationValue => f.write_str(
58                "expected the start of an RFC 9557 annotation value, \
59                 but found end of input instead",
60            ),
61            EndOfInputTzAnnotationClose => f.write_str(
62                "expected an `]` after parsing an RFC 9557 time zone \
63                 annotation, but found end of input instead",
64            ),
65            UnexpectedByteAnnotation { byte } => f.write_fmt(format_args!("expected ASCII alphabetic byte (or underscore or period) at the start of an RFC 9557 annotation or time zone component name, but found `{0}` instead",
        escape::Byte(byte)))write!(
66                f,
67                "expected ASCII alphabetic byte (or underscore or period) \
68                 at the start of an RFC 9557 annotation or time zone \
69                 component name, but found `{byte}` instead",
70                byte = escape::Byte(byte),
71            ),
72            UnexpectedByteAnnotationClose { byte } => f.write_fmt(format_args!("expected an `]` after parsing an RFC 9557 annotation key and value, but found `{0}` instead",
        escape::Byte(byte)))write!(
73                f,
74                "expected an `]` after parsing an RFC 9557 annotation key \
75                 and value, but found `{byte}` instead",
76                byte = escape::Byte(byte),
77            ),
78            UnexpectedByteAnnotationKey { byte } => f.write_fmt(format_args!("expected lowercase alphabetic byte (or underscore) at the start of an RFC 9557 annotation key, but found `{0}` instead",
        escape::Byte(byte)))write!(
79                f,
80                "expected lowercase alphabetic byte (or underscore) \
81                 at the start of an RFC 9557 annotation key, \
82                 but found `{byte}` instead",
83                byte = escape::Byte(byte),
84            ),
85            UnexpectedByteAnnotationValue { byte } => f.write_fmt(format_args!("expected alphanumeric ASCII byte at the start of an RFC 9557 annotation value, but found `{0}` instead",
        escape::Byte(byte)))write!(
86                f,
87                "expected alphanumeric ASCII byte \
88                 at the start of an RFC 9557 annotation value, \
89                 but found `{byte}` instead",
90                byte = escape::Byte(byte),
91            ),
92            UnexpectedByteAnnotationSeparator { byte } => f.write_fmt(format_args!("expected an `=` after parsing an RFC 9557 annotation key, but found `{0}` instead",
        escape::Byte(byte)))write!(
93                f,
94                "expected an `=` after parsing an RFC 9557 annotation \
95                 key, but found `{byte}` instead",
96                byte = escape::Byte(byte),
97            ),
98            UnexpectedByteTzAnnotationClose { byte } => f.write_fmt(format_args!("expected an `]` after parsing an RFC 9557 time zone annotation, but found `{0}` instead",
        escape::Byte(byte)))write!(
99                f,
100                "expected an `]` after parsing an RFC 9557 time zone \
101                 annotation, but found `{byte}` instead",
102                byte = escape::Byte(byte),
103            ),
104            UnexpectedSlashAnnotationSeparator => f.write_str(
105                "expected an `=` after parsing an RFC 9557 annotation \
106                 key, but found `/` instead (time zone annotations must \
107                 come first)",
108            ),
109            UnsupportedAnnotationCritical => f.write_str(
110                "found unsupported RFC 9557 annotation \
111                 with the critical flag (`!`) set",
112            ),
113        }
114    }
115}