-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patherror.rs
More file actions
38 lines (33 loc) · 1023 Bytes
/
error.rs
File metadata and controls
38 lines (33 loc) · 1023 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use camino::Utf8PathBuf;
use snafu::prelude::*;
#[derive(Clone, Debug, PartialEq)]
pub struct NormalizeError {
pub path: Utf8PathBuf,
pub kind: NormalizeErrorKind,
}
impl NormalizeError {
pub fn new(path: Utf8PathBuf, kind: NormalizeErrorKind) -> Self {
Self { path, kind }
}
}
impl std::error::Error for NormalizeError {}
#[derive(Clone, Debug, PartialEq, Snafu)]
pub enum NormalizeErrorKind {
#[snafu(display("path cannot be empty"))]
EmptyNotAllowed,
#[snafu(display("`..` not allowed in path"))]
ParentNotAllowed,
#[snafu(display("`.` not allowed in path"))]
CurrentDirNotAllowed,
#[snafu(display("Path must relative"))]
AbsoluteNotAllowed,
#[snafu(display("Path must absolute"))]
AbsoluteRequired,
#[snafu(display("Component cannot contain slash"))]
SlashForbidden,
}
impl std::fmt::Display for NormalizeError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}{}", self.path, self.kind)
}
}