#[derive(Debug, Clone)]
pub enum ErrorKind {
Parse,
MissingValues,
UnsupportedFormatSpec,
}
#[derive(Debug)]
pub struct Error {
message: String,
kind: ErrorKind,
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.message)
}
}
impl std::error::Error for Error {}
impl Error {
pub(crate) fn new_parse(message: String) -> Self {
Self {
message,
kind: ErrorKind::Parse,
}
}
pub(crate) fn new_values(message: String) -> Self {
Self {
message,
kind: ErrorKind::MissingValues,
}
}
pub(crate) fn new_ufs(message: String) -> Self {
Self {
message,
kind: ErrorKind::UnsupportedFormatSpec,
}
}
pub fn message(&self) -> String {
self.message.clone()
}
pub fn kind(&self) -> ErrorKind {
self.kind.clone()
}
}