1use std::fmt;
2
3#[derive(Debug, Clone, PartialEq, Eq)]
5pub enum PathError {
6 InvalidPath(String),
8
9 EncodingError(String),
11
12 SecurityError(String),
14
15 PlatformError(String),
17
18 NormalizationError(String),
20
21 ParseError(String),
23
24 IoError(String),
26
27 UnsupportedFormat(String),
29
30 DriveMappingError(String),
32}
33
34impl PathError {
35 pub fn invalid_path(msg: impl Into<String>) -> Self {
37 Self::InvalidPath(msg.into())
38 }
39
40 pub fn encoding_error(msg: impl Into<String>) -> Self {
42 Self::EncodingError(msg.into())
43 }
44
45 pub fn security_error(msg: impl Into<String>) -> Self {
47 Self::SecurityError(msg.into())
48 }
49
50 pub fn platform_error(msg: impl Into<String>) -> Self {
52 Self::PlatformError(msg.into())
53 }
54}
55
56impl fmt::Display for PathError {
57 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
58 match self {
59 Self::InvalidPath(msg) => write!(f, "Invalid path: {msg}"),
60 Self::EncodingError(msg) => write!(f, "Encoding error: {msg}"),
61 Self::SecurityError(msg) => write!(f, "Security error: {msg}"),
62 Self::PlatformError(msg) => write!(f, "Platform error: {msg}"),
63 Self::NormalizationError(msg) => write!(f, "Normalization error: {msg}"),
64 Self::ParseError(msg) => write!(f, "Parse error: {msg}"),
65 Self::IoError(msg) => write!(f, "IO error: {msg}"),
66 Self::UnsupportedFormat(msg) => write!(f, "Unsupported format: {msg}"),
67 Self::DriveMappingError(msg) => write!(f, "Drive mapping error: {msg}"),
68 }
69 }
70}
71
72impl std::error::Error for PathError {}
73
74impl From<std::io::Error> for PathError {
75 fn from(err: std::io::Error) -> Self {
76 Self::IoError(err.to_string())
77 }
78}