use std::fmt;
#[derive(Debug)]
pub enum PergError {
Io(std::io::Error),
Regex(regex::Error),
FileNotFound(String),
InvalidPattern(String),
}
impl fmt::Display for PergError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
PergError::Io(err) => write!(f, "I/O error: {}", err),
PergError::Regex(err) => write!(f, "Regex error: {}", err),
PergError::FileNotFound(path) => write!(f, "File not found: {}", path),
PergError::InvalidPattern(pattern) => write!(f, "Invalid pattern: {}", pattern),
}
}
}
impl std::error::Error for PergError {}
impl From<std::io::Error> for PergError {
fn from(err: std::io::Error) -> Self {
PergError::Io(err)
}
}
impl From<regex::Error> for PergError {
fn from(err: regex::Error) -> Self {
PergError::Regex(err)
}
}
pub type Result<T> = std::result::Result<T, PergError>;