Skip to main content

time/error/
invalid_format_description.rs

1//! Invalid format description
2
3use alloc::string::String;
4use core::fmt;
5
6use crate::error;
7
8/// The format description provided was not valid.
9#[non_exhaustive]
10#[derive(#[automatically_derived]
impl ::core::fmt::Debug for InvalidFormatDescription {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            InvalidFormatDescription::UnclosedOpeningBracket { index: __self_0
                } =>
                ::core::fmt::Formatter::debug_struct_field1_finish(f,
                    "UnclosedOpeningBracket", "index", &__self_0),
            InvalidFormatDescription::InvalidComponentName {
                name: __self_0, index: __self_1 } =>
                ::core::fmt::Formatter::debug_struct_field2_finish(f,
                    "InvalidComponentName", "name", __self_0, "index",
                    &__self_1),
            InvalidFormatDescription::InvalidModifier {
                value: __self_0, index: __self_1 } =>
                ::core::fmt::Formatter::debug_struct_field2_finish(f,
                    "InvalidModifier", "value", __self_0, "index", &__self_1),
            InvalidFormatDescription::MissingComponentName { index: __self_0 }
                =>
                ::core::fmt::Formatter::debug_struct_field1_finish(f,
                    "MissingComponentName", "index", &__self_0),
            InvalidFormatDescription::MissingRequiredModifier {
                name: __self_0, index: __self_1 } =>
                ::core::fmt::Formatter::debug_struct_field2_finish(f,
                    "MissingRequiredModifier", "name", __self_0, "index",
                    &__self_1),
            InvalidFormatDescription::Expected {
                what: __self_0, index: __self_1 } =>
                ::core::fmt::Formatter::debug_struct_field2_finish(f,
                    "Expected", "what", __self_0, "index", &__self_1),
            InvalidFormatDescription::NotSupported {
                what: __self_0, context: __self_1, index: __self_2 } =>
                ::core::fmt::Formatter::debug_struct_field3_finish(f,
                    "NotSupported", "what", __self_0, "context", __self_1,
                    "index", &__self_2),
            InvalidFormatDescription::DuplicateModifier {
                name: __self_0, index: __self_1 } =>
                ::core::fmt::Formatter::debug_struct_field2_finish(f,
                    "DuplicateModifier", "name", __self_0, "index", &__self_1),
            InvalidFormatDescription::InvalidModifierCombination {
                modifier: __self_0, context: __self_1, index: __self_2 } =>
                ::core::fmt::Formatter::debug_struct_field3_finish(f,
                    "InvalidModifierCombination", "modifier", __self_0,
                    "context", __self_1, "index", &__self_2),
        }
    }
}Debug, #[automatically_derived]
impl ::core::clone::Clone for InvalidFormatDescription {
    #[inline]
    fn clone(&self) -> InvalidFormatDescription {
        match self {
            InvalidFormatDescription::UnclosedOpeningBracket { index: __self_0
                } =>
                InvalidFormatDescription::UnclosedOpeningBracket {
                    index: ::core::clone::Clone::clone(__self_0),
                },
            InvalidFormatDescription::InvalidComponentName {
                name: __self_0, index: __self_1 } =>
                InvalidFormatDescription::InvalidComponentName {
                    name: ::core::clone::Clone::clone(__self_0),
                    index: ::core::clone::Clone::clone(__self_1),
                },
            InvalidFormatDescription::InvalidModifier {
                value: __self_0, index: __self_1 } =>
                InvalidFormatDescription::InvalidModifier {
                    value: ::core::clone::Clone::clone(__self_0),
                    index: ::core::clone::Clone::clone(__self_1),
                },
            InvalidFormatDescription::MissingComponentName { index: __self_0 }
                =>
                InvalidFormatDescription::MissingComponentName {
                    index: ::core::clone::Clone::clone(__self_0),
                },
            InvalidFormatDescription::MissingRequiredModifier {
                name: __self_0, index: __self_1 } =>
                InvalidFormatDescription::MissingRequiredModifier {
                    name: ::core::clone::Clone::clone(__self_0),
                    index: ::core::clone::Clone::clone(__self_1),
                },
            InvalidFormatDescription::Expected {
                what: __self_0, index: __self_1 } =>
                InvalidFormatDescription::Expected {
                    what: ::core::clone::Clone::clone(__self_0),
                    index: ::core::clone::Clone::clone(__self_1),
                },
            InvalidFormatDescription::NotSupported {
                what: __self_0, context: __self_1, index: __self_2 } =>
                InvalidFormatDescription::NotSupported {
                    what: ::core::clone::Clone::clone(__self_0),
                    context: ::core::clone::Clone::clone(__self_1),
                    index: ::core::clone::Clone::clone(__self_2),
                },
            InvalidFormatDescription::DuplicateModifier {
                name: __self_0, index: __self_1 } =>
                InvalidFormatDescription::DuplicateModifier {
                    name: ::core::clone::Clone::clone(__self_0),
                    index: ::core::clone::Clone::clone(__self_1),
                },
            InvalidFormatDescription::InvalidModifierCombination {
                modifier: __self_0, context: __self_1, index: __self_2 } =>
                InvalidFormatDescription::InvalidModifierCombination {
                    modifier: ::core::clone::Clone::clone(__self_0),
                    context: ::core::clone::Clone::clone(__self_1),
                    index: ::core::clone::Clone::clone(__self_2),
                },
        }
    }
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for InvalidFormatDescription {
    #[inline]
    fn eq(&self, other: &InvalidFormatDescription) -> bool {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        __self_discr == __arg1_discr &&
            match (self, other) {
                (InvalidFormatDescription::UnclosedOpeningBracket {
                    index: __self_0 },
                    InvalidFormatDescription::UnclosedOpeningBracket {
                    index: __arg1_0 }) => __self_0 == __arg1_0,
                (InvalidFormatDescription::InvalidComponentName {
                    name: __self_0, index: __self_1 },
                    InvalidFormatDescription::InvalidComponentName {
                    name: __arg1_0, index: __arg1_1 }) =>
                    __self_0 == __arg1_0 && __self_1 == __arg1_1,
                (InvalidFormatDescription::InvalidModifier {
                    value: __self_0, index: __self_1 },
                    InvalidFormatDescription::InvalidModifier {
                    value: __arg1_0, index: __arg1_1 }) =>
                    __self_0 == __arg1_0 && __self_1 == __arg1_1,
                (InvalidFormatDescription::MissingComponentName {
                    index: __self_0 },
                    InvalidFormatDescription::MissingComponentName {
                    index: __arg1_0 }) => __self_0 == __arg1_0,
                (InvalidFormatDescription::MissingRequiredModifier {
                    name: __self_0, index: __self_1 },
                    InvalidFormatDescription::MissingRequiredModifier {
                    name: __arg1_0, index: __arg1_1 }) =>
                    __self_0 == __arg1_0 && __self_1 == __arg1_1,
                (InvalidFormatDescription::Expected {
                    what: __self_0, index: __self_1 },
                    InvalidFormatDescription::Expected {
                    what: __arg1_0, index: __arg1_1 }) =>
                    __self_0 == __arg1_0 && __self_1 == __arg1_1,
                (InvalidFormatDescription::NotSupported {
                    what: __self_0, context: __self_1, index: __self_2 },
                    InvalidFormatDescription::NotSupported {
                    what: __arg1_0, context: __arg1_1, index: __arg1_2 }) =>
                    __self_0 == __arg1_0 && __self_1 == __arg1_1 &&
                        __self_2 == __arg1_2,
                (InvalidFormatDescription::DuplicateModifier {
                    name: __self_0, index: __self_1 },
                    InvalidFormatDescription::DuplicateModifier {
                    name: __arg1_0, index: __arg1_1 }) =>
                    __self_0 == __arg1_0 && __self_1 == __arg1_1,
                (InvalidFormatDescription::InvalidModifierCombination {
                    modifier: __self_0, context: __self_1, index: __self_2 },
                    InvalidFormatDescription::InvalidModifierCombination {
                    modifier: __arg1_0, context: __arg1_1, index: __arg1_2 }) =>
                    __self_0 == __arg1_0 && __self_1 == __arg1_1 &&
                        __self_2 == __arg1_2,
                _ => unsafe { ::core::intrinsics::unreachable() }
            }
    }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for InvalidFormatDescription {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {
        let _: ::core::cmp::AssertParamIsEq<usize>;
        let _: ::core::cmp::AssertParamIsEq<String>;
        let _: ::core::cmp::AssertParamIsEq<&'static str>;
        let _: ::core::cmp::AssertParamIsEq<&'static str>;
        let _: ::core::cmp::AssertParamIsEq<&'static str>;
        let _: ::core::cmp::AssertParamIsEq<&'static str>;
        let _: ::core::cmp::AssertParamIsEq<&'static str>;
        let _: ::core::cmp::AssertParamIsEq<&'static str>;
        let _: ::core::cmp::AssertParamIsEq<&'static str>;
    }
}Eq)]
11pub enum InvalidFormatDescription {
12    /// There was a bracket pair that was opened but not closed.
13    #[non_exhaustive]
14    UnclosedOpeningBracket {
15        /// The zero-based index of the opening bracket.
16        index: usize,
17    },
18    /// A component name is not valid.
19    #[non_exhaustive]
20    InvalidComponentName {
21        /// The name of the invalid component name.
22        name: String,
23        /// The zero-based index the component name starts at.
24        index: usize,
25    },
26    /// A modifier is not valid.
27    #[non_exhaustive]
28    InvalidModifier {
29        /// The value of the invalid modifier.
30        value: String,
31        /// The zero-based index the modifier starts at.
32        index: usize,
33    },
34    /// A component name is missing.
35    #[non_exhaustive]
36    MissingComponentName {
37        /// The zero-based index where the component name should start.
38        index: usize,
39    },
40    /// A required modifier is missing.
41    #[non_exhaustive]
42    MissingRequiredModifier {
43        /// The name of the modifier that is missing.
44        name: &'static str,
45        /// The zero-based index of the component.
46        index: usize,
47    },
48    /// Something was expected, but not found.
49    #[non_exhaustive]
50    Expected {
51        /// What was expected to be present, but wasn't.
52        what: &'static str,
53        /// The zero-based index the item was expected to be found at.
54        index: usize,
55    },
56    /// Certain behavior is not supported in the given context.
57    #[non_exhaustive]
58    NotSupported {
59        /// The behavior that is not supported.
60        what: &'static str,
61        /// The context in which the behavior is not supported.
62        context: &'static str,
63        /// The zero-based index the error occurred at.
64        index: usize,
65    },
66    /// A modifier was present more than once.
67    #[non_exhaustive]
68    DuplicateModifier {
69        /// The name of the modifier that is duplicated.
70        name: &'static str,
71        /// The zero-based index of the second occurrence of the modifier.
72        index: usize,
73    },
74    /// A combination of modifiers is not valid.
75    #[non_exhaustive]
76    InvalidModifierCombination {
77        /// The modifier that is not valid in combination with the other modifiers.
78        modifier: &'static str,
79        /// The context in which the modifier is not valid.
80        context: &'static str,
81        /// The zero-based index the error occurred at.
82        index: usize,
83    },
84}
85
86impl From<InvalidFormatDescription> for crate::Error {
87    #[inline]
88    fn from(original: InvalidFormatDescription) -> Self {
89        Self::InvalidFormatDescription(original)
90    }
91}
92
93impl TryFrom<crate::Error> for InvalidFormatDescription {
94    type Error = error::DifferentVariant;
95
96    #[inline]
97    fn try_from(err: crate::Error) -> Result<Self, Self::Error> {
98        match err {
99            crate::Error::InvalidFormatDescription(err) => Ok(err),
100            _ => Err(error::DifferentVariant),
101        }
102    }
103}
104
105impl fmt::Display for InvalidFormatDescription {
106    #[inline]
107    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
108        use InvalidFormatDescription::*;
109        match self {
110            UnclosedOpeningBracket { index } => {
111                f.write_fmt(format_args!("unclosed opening bracket at byte index {0}", index))write!(f, "unclosed opening bracket at byte index {index}")
112            }
113            InvalidComponentName { name, index } => {
114                f.write_fmt(format_args!("invalid component name `{0}` at byte index {1}",
        name, index))write!(f, "invalid component name `{name}` at byte index {index}")
115            }
116            InvalidModifier { value, index } => {
117                f.write_fmt(format_args!("invalid modifier `{0}` at byte index {1}", value,
        index))write!(f, "invalid modifier `{value}` at byte index {index}")
118            }
119            MissingComponentName { index } => {
120                f.write_fmt(format_args!("missing component name at byte index {0}", index))write!(f, "missing component name at byte index {index}")
121            }
122            MissingRequiredModifier { name, index } => {
123                f.write_fmt(format_args!("missing required modifier `{0}` for component at byte index {1}",
        name, index))write!(
124                    f,
125                    "missing required modifier `{name}` for component at byte index {index}"
126                )
127            }
128            Expected {
129                what: expected,
130                index,
131            } => {
132                f.write_fmt(format_args!("expected {0} at byte index {1}", expected, index))write!(f, "expected {expected} at byte index {index}")
133            }
134            NotSupported {
135                what,
136                context,
137                index,
138            } => {
139                if context.is_empty() {
140                    f.write_fmt(format_args!("{0} is not supported at byte index {1}", what,
        index))write!(f, "{what} is not supported at byte index {index}")
141                } else {
142                    f.write_fmt(format_args!("{0} is not supported in {1} at byte index {2}",
        what, context, index))write!(
143                        f,
144                        "{what} is not supported in {context} at byte index {index}"
145                    )
146                }
147            }
148            DuplicateModifier { name, index } => {
149                f.write_fmt(format_args!("duplicate modifier `{0}` at byte index {1}", name,
        index))write!(f, "duplicate modifier `{name}` at byte index {index}")
150            }
151            InvalidModifierCombination {
152                modifier,
153                context,
154                index,
155            } => f.write_fmt(format_args!("the `{0}` modifier is not valid at byte index {1} {2}",
        modifier, index, context))write!(
156                f,
157                "the `{modifier}` modifier is not valid at byte index {index} {context}"
158            ),
159        }
160    }
161}
162
163impl core::error::Error for InvalidFormatDescription {}