use std::fmt;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum PathError {
InvalidPath(String),
EncodingError(String),
SecurityError(String),
PlatformError(String),
NormalizationError(String),
ParseError(String),
IoError(String),
UnsupportedFormat(String),
DriveMappingError(String),
}
impl PathError {
pub fn invalid_path(msg: impl Into<String>) -> Self {
Self::InvalidPath(msg.into())
}
pub fn encoding_error(msg: impl Into<String>) -> Self {
Self::EncodingError(msg.into())
}
pub fn security_error(msg: impl Into<String>) -> Self {
Self::SecurityError(msg.into())
}
pub fn platform_error(msg: impl Into<String>) -> Self {
Self::PlatformError(msg.into())
}
}
impl fmt::Display for PathError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::InvalidPath(msg) => write!(f, "Invalid path: {msg}"),
Self::EncodingError(msg) => write!(f, "Encoding error: {msg}"),
Self::SecurityError(msg) => write!(f, "Security error: {msg}"),
Self::PlatformError(msg) => write!(f, "Platform error: {msg}"),
Self::NormalizationError(msg) => write!(f, "Normalization error: {msg}"),
Self::ParseError(msg) => write!(f, "Parse error: {msg}"),
Self::IoError(msg) => write!(f, "IO error: {msg}"),
Self::UnsupportedFormat(msg) => write!(f, "Unsupported format: {msg}"),
Self::DriveMappingError(msg) => write!(f, "Drive mapping error: {msg}"),
}
}
}
impl std::error::Error for PathError {}
impl From<std::io::Error> for PathError {
fn from(err: std::io::Error) -> Self {
Self::IoError(err.to_string())
}
}