use std::fmt::{Display, Formatter};
#[derive(Debug)]
pub enum Error {
BadRegex(regex::Error),
NoMatch(),
BadValue {
name: String,
value: String,
},
Custom(String),
}
impl serde::de::Error for Error {
fn custom<T>(msg: T) -> Self where T: Display {
Self::Custom(msg.to_string())
}
}
impl std::error::Error for Error {}
impl Display for Error {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
use Error::*;
match self {
BadRegex(err) => err.fmt(f),
NoMatch() => write!(f, "String doesn't match pattern"),
BadValue { name, value } => write!(f, "Unable to convert value for group {}: {}", name, value),
Custom(err) => write!(f, "{}", err),
}
}
}
pub(crate) type Result<T> = std::result::Result<T, Error>;