jiff/error/fmt/
friendly.rs1use 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::Empty => Error::Empty,
Self::ExpectedColonAfterMinute => Error::ExpectedColonAfterMinute,
Self::ExpectedIntegerAfterSign => Error::ExpectedIntegerAfterSign,
Self::ExpectedMinuteAfterHour => Error::ExpectedMinuteAfterHour,
Self::ExpectedOneMoreUnitAfterComma =>
Error::ExpectedOneMoreUnitAfterComma,
Self::ExpectedOneSign => Error::ExpectedOneSign,
Self::ExpectedSecondAfterMinute =>
Error::ExpectedSecondAfterMinute,
Self::ExpectedUnitSuffix => Error::ExpectedUnitSuffix,
Self::ExpectedWhitespaceAfterComma { byte: __self_0 } =>
Error::ExpectedWhitespaceAfterComma {
byte: ::core::clone::Clone::clone(__self_0),
},
Self::ExpectedWhitespaceAfterCommaEndOfInput =>
Error::ExpectedWhitespaceAfterCommaEndOfInput,
Self::Failed => Error::Failed,
}
}
}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::Empty => ::core::fmt::Formatter::write_str(f, "Empty"),
Self::ExpectedColonAfterMinute =>
::core::fmt::Formatter::write_str(f,
"ExpectedColonAfterMinute"),
Self::ExpectedIntegerAfterSign =>
::core::fmt::Formatter::write_str(f,
"ExpectedIntegerAfterSign"),
Self::ExpectedMinuteAfterHour =>
::core::fmt::Formatter::write_str(f,
"ExpectedMinuteAfterHour"),
Self::ExpectedOneMoreUnitAfterComma =>
::core::fmt::Formatter::write_str(f,
"ExpectedOneMoreUnitAfterComma"),
Self::ExpectedOneSign =>
::core::fmt::Formatter::write_str(f, "ExpectedOneSign"),
Self::ExpectedSecondAfterMinute =>
::core::fmt::Formatter::write_str(f,
"ExpectedSecondAfterMinute"),
Self::ExpectedUnitSuffix =>
::core::fmt::Formatter::write_str(f, "ExpectedUnitSuffix"),
Self::ExpectedWhitespaceAfterComma { byte: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"ExpectedWhitespaceAfterComma byte", &__self_0),
Self::ExpectedWhitespaceAfterCommaEndOfInput =>
::core::fmt::Formatter::write_str(f,
"ExpectedWhitespaceAfterCommaEndOfInput"),
Self::Failed => ::core::fmt::Formatter::write_str(f, "Failed"),
}
}
}Debug)]
4#[cfg_attr(feature = "defmt", derive(defmt::Format))]
5pub(crate) enum Error {
6 Empty,
7 ExpectedColonAfterMinute,
8 ExpectedIntegerAfterSign,
9 ExpectedMinuteAfterHour,
10 ExpectedOneMoreUnitAfterComma,
11 ExpectedOneSign,
12 ExpectedSecondAfterMinute,
13 ExpectedUnitSuffix,
14 ExpectedWhitespaceAfterComma { byte: u8 },
15 ExpectedWhitespaceAfterCommaEndOfInput,
16 Failed,
17}
18
19impl error::IntoError for Error {
20 fn into_error(self) -> error::Error {
21 self.into()
22 }
23}
24
25impl From<Error> for error::Error {
26 #[cold]
27 #[inline(never)]
28 fn from(err: Error) -> error::Error {
29 error::ErrorKind::FmtFriendly(err).into()
30 }
31}
32
33impl core::fmt::Display for Error {
34 fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
35 use self::Error::*;
36
37 match *self {
38 Empty => f.write_str("an empty string is not valid"),
39 ExpectedColonAfterMinute => f.write_str(
40 "when parsing the `HH:MM:SS` format, \
41 expected to parse `:` following minute",
42 ),
43 ExpectedIntegerAfterSign => f.write_str(
44 "expected duration to start \
45 with a unit value (a decimal integer) after an \
46 optional sign, but no integer was found",
47 ),
48 ExpectedMinuteAfterHour => f.write_str(
49 "when parsing the `HH:MM:SS` format, \
50 expected to parse minute following hour",
51 ),
52 ExpectedOneMoreUnitAfterComma => f.write_str(
53 "found comma at the end of duration, \
54 but a comma indicates at least one more \
55 unit follows",
56 ),
57 ExpectedOneSign => f.write_str(
58 "expected to find either a prefix sign (+/-) or \
59 a suffix sign (`ago`), but found both",
60 ),
61 ExpectedSecondAfterMinute => f.write_str(
62 "when parsing the `HH:MM:SS` format, \
63 expected to parse second following minute",
64 ),
65 ExpectedUnitSuffix => f.write_str(
66 "expected to find unit designator suffix \
67 (e.g., `years` or `secs`) after parsing \
68 integer",
69 ),
70 ExpectedWhitespaceAfterComma { byte } => f.write_fmt(format_args!("expected whitespace after comma, but found `{0}`",
escape::Byte(byte)))write!(
71 f,
72 "expected whitespace after comma, but found `{byte}`",
73 byte = escape::Byte(byte),
74 ),
75 ExpectedWhitespaceAfterCommaEndOfInput => f.write_str(
76 "expected whitespace after comma, but found end of input",
77 ),
78 Failed => f.write_str(
79 "failed to parse input in the \"friendly\" duration format",
80 ),
81 }
82 }
83}