pub enum Error {
UnsupportedSpec(FormatSpec),
ArgumentCountMismatch(usize, usize),
Parse(Box<Error<Rule>>),
Write(Error),
NamedArgument(String),
}Expand description
Errors that can occur during dynamic formatting.
This enum represents all possible errors that can occur during the parsing and application of format specifications.
Variants§
UnsupportedSpec(FormatSpec)
An unsupported format specification was encountered.
This error occurs when a format specification contains options or combinations that are not supported by the formatting machinery.
ArgumentCountMismatch(usize, usize)
The number of arguments doesn’t match the number of format specifications.
This error occurs when the number of arguments provided to a format string doesn’t match the number of format specifications in the string.
§Examples
Providing too few arguments:
use dyf::{FormatString, dformat, Error};
let fmt = FormatString::from_string("{}, {}".to_string()).unwrap();
let result = dformat!(&fmt, "only one argument");
assert!(matches!(result, Err(Error::ArgumentCountMismatch(2, 1))));Providing too many arguments:
use dyf::{FormatString, dformat, Error};
let fmt = FormatString::from_string("{}".to_string()).unwrap();
let result = dformat!(&fmt, "one", "extra");
assert!(matches!(result, Err(Error::ArgumentCountMismatch(1, 2))));Parse(Box<Error<Rule>>)
An error occurred during format string parsing.
This error wraps parsing errors from the underlying pest parser and provides
information about syntax errors in format strings.
Write(Error)
A write error occurred while writing formatted output.
NamedArgument(String)
Named or positional argument syntax ({0}, {name}) is not supported.
Arguments are always matched positionally in the order they are passed.
Trait Implementations§
Source§impl Error for Error
impl Error for Error
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()