easyofd_reader/
error_path_exception.rs1use thiserror::Error;
6
7#[derive(Debug, Error)]
13#[non_exhaustive]
14pub enum ErrorPathException {
15 #[error("无法切换路径到 {path},目录不存在")]
17 PathNotFound {
18 path: String,
20 },
21
22 #[error("路径为空")]
24 EmptyPath,
25
26 #[error("路径越界: {path}")]
28 OutOfBounds {
29 path: String,
31 },
32}
33
34impl ErrorPathException {
35 pub fn not_found(path: impl Into<String>) -> Self {
37 Self::PathNotFound { path: path.into() }
38 }
39
40 pub fn empty() -> Self {
42 Self::EmptyPath
43 }
44
45 pub fn out_of_bounds(path: impl Into<String>) -> Self {
47 Self::OutOfBounds { path: path.into() }
48 }
49}
50
51#[cfg(test)]
52mod tests {
53 use super::*;
54
55 #[test]
56 fn test_path_not_found() {
57 let e = ErrorPathException::not_found("/Doc_0/Res");
58 assert!(e.to_string().contains("/Doc_0/Res"));
59 assert!(e.to_string().contains("不存在"));
60 }
61
62 #[test]
63 fn test_empty_path() {
64 let e = ErrorPathException::empty();
65 assert!(e.to_string().contains("为空"));
66 }
67
68 #[test]
69 fn test_out_of_bounds() {
70 let e = ErrorPathException::out_of_bounds("../../..");
71 assert!(e.to_string().contains("../../.."));
72 }
73}