use std::fmt::Display;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Error {
pub field: String,
pub message: String,
}
impl Error {
pub fn new(message: impl Into<String>) -> Self {
Self {
field: String::new(),
message: message.into(),
}
}
pub fn set_field(mut self, field: impl Into<String>) -> Self {
self.field = field.into();
self
}
}
impl Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"error preprocessing field `{}`: {}",
self.field, self.message
)
}
}
impl std::error::Error for Error {}