use std::fmt;
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct FieldError {
pub path: String,
pub problem: String,
}
impl fmt::Display for FieldError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "`{}` {}", self.path, self.problem)
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum ManifestError {
Syntax(String),
Fields(Vec<FieldError>),
}
impl fmt::Display for ManifestError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Syntax(message) => write!(f, "the manifest is not TOML: {message}"),
Self::Fields(problems) => {
f.write_str("the manifest is not valid:")?;
for problem in problems {
write!(f, "\n {problem}")?;
}
Ok(())
}
}
}
}
impl std::error::Error for ManifestError {}
#[derive(Default)]
pub(crate) struct Problems(Vec<FieldError>);
impl Problems {
pub(crate) fn add(&mut self, path: String, problem: impl Into<String>) {
self.0.push(FieldError {
path,
problem: problem.into(),
});
}
pub(crate) fn into_list(self) -> Vec<FieldError> {
self.0
}
}