1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use core::fmt;
/// Error returned by [`Format::try_format`](crate::Format::try_format).
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum FormatError {
/// A placeholder index is beyond the number of supplied arguments.
InsufficientParameters,
/// The template is syntactically invalid (unbalanced braces, named
/// arguments, an illegal spec, ...).
InvalidFormatString,
/// The argument does not support the requested format type (e.g. `{:x}`
/// on a string, or the unsupported `{:p}`).
UnsupportedFormatType,
/// The argument referenced by `{:1$}` / `{:.1$}` as a width/precision is
/// not an unsigned integer.
ExpectedUsize,
/// The output sink rejected a write (`fmt::Write::write_str` returned
/// `Err`). Writing into a `String` never fails.
WriteFailed,
}
impl fmt::Display for FormatError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
FormatError::InsufficientParameters => write!(f, "Insufficient parameters"),
FormatError::InvalidFormatString => write!(f, "Invalid format string"),
FormatError::UnsupportedFormatType => {
write!(f, "Argument does not support the requested format type")
}
FormatError::ExpectedUsize => {
write!(f, "Width/precision argument must be an unsigned integer")
}
FormatError::WriteFailed => write!(f, "Failed to write to the output sink"),
}
}
}
impl core::error::Error for FormatError {}