#[cfg(feature = "regex_support")]
use regex::Error as RErr;
use std::error::Error;
use std::fmt::{Display, Formatter};
use std::io;
use std::path::PathBuf;
#[derive(Debug)]
pub enum TempError {
FileIsNone,
InvalidFileOrPath,
IO(io::Error),
#[cfg(feature = "regex_support")]
Regex(RErr),
FileExists(PathBuf),
}
impl Display for TempError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Self::FileIsNone => write!(f, "File is None"),
Self::InvalidFileOrPath => write!(f, "File or path is invalid"),
Self::IO(e) => write!(f, "IO error: {e}"),
#[cfg(feature = "regex_support")]
Self::Regex(e) => write!(f, "Regex error: {e}"),
Self::FileExists(path) => write!(f, "Entry at path already exists: {}", path.display()),
}
}
}
impl Error for TempError {}
pub type TempResult<T> = Result<T, TempError>;
impl From<io::Error> for TempError {
fn from(e: io::Error) -> Self {
Self::IO(e)
}
}
#[cfg(feature = "regex_support")]
impl From<RErr> for TempError {
fn from(e: RErr) -> Self {
Self::Regex(e)
}
}
#[derive(Debug)]
pub enum FsError {
NotFound(String),
AlreadyExists(String),
InvalidPath(String),
}
impl Display for FsError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Self::NotFound(path) => write!(f, "Could not find file: {path}"),
Self::AlreadyExists(path) => write!(f, "File already exists: {path}"),
Self::InvalidPath(path) => write!(f, "Invalid path: {path}"),
}
}
}
impl Error for FsError {}