1 //! Invalid format description
3 use alloc
::string
::String
;
8 /// The format description provided was not valid.
10 #[derive(Debug, Clone, PartialEq, Eq)]
11 pub enum InvalidFormatDescription
{
12 /// There was a bracket pair that was opened but not closed.
14 UnclosedOpeningBracket
{
15 /// The zero-based index of the opening bracket.
18 /// A component name is not valid.
20 InvalidComponentName
{
21 /// The name of the invalid component name.
23 /// The zero-based index the component name starts at.
26 /// A modifier is not valid.
29 /// The value of the invalid modifier.
31 /// The zero-based index the modifier starts at.
34 /// A component name is missing.
36 MissingComponentName
{
37 /// The zero-based index where the component name should start.
42 impl From
<InvalidFormatDescription
> for crate::Error
{
43 fn from(original
: InvalidFormatDescription
) -> Self {
44 Self::InvalidFormatDescription(original
)
48 impl TryFrom
<crate::Error
> for InvalidFormatDescription
{
49 type Error
= error
::DifferentVariant
;
51 fn try_from(err
: crate::Error
) -> Result
<Self, Self::Error
> {
53 crate::Error
::InvalidFormatDescription(err
) => Ok(err
),
54 _
=> Err(error
::DifferentVariant
),
59 impl fmt
::Display
for InvalidFormatDescription
{
60 fn fmt(&self, f
: &mut fmt
::Formatter
<'_
>) -> fmt
::Result
{
61 use InvalidFormatDescription
::*;
63 UnclosedOpeningBracket { index }
=> {
64 write
!(f
, "unclosed opening bracket at byte index {index}")
66 InvalidComponentName { name, index }
=> {
67 write
!(f
, "invalid component name `{name}` at byte index {index}")
69 InvalidModifier { value, index }
=> {
70 write
!(f
, "invalid modifier `{value}` at byte index {index}")
72 MissingComponentName { index }
=> {
73 write
!(f
, "missing component name at byte index {index}")
79 #[cfg(feature = "std")]
80 impl std
::error
::Error
for InvalidFormatDescription {}