summary refs log tree commit diff
path: root/src/path/error.rs
blob: 0ee54236d64c7fefa5ecb57c936f97a20db20282 (plain)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
#[derive(Clone,Debug,Eq,Hash,Ord,PartialEq,PartialOrd)]
pub enum FileNameError {
  ContainsSlash(String),
}

#[derive(Clone,Debug,Eq,Hash,Ord,PartialEq,PartialOrd)]
pub enum DirectoryNameError {
  ContainsSlash(String),
}

#[derive(Clone,Debug,Eq,Hash,Ord,PartialEq,PartialOrd)]
pub enum PathError {
  Parse(String),
}


impl std::error::Error for FileNameError { }

impl std::error::Error for DirectoryNameError { }

impl std::error::Error for PathError { }

impl std::fmt::Display for FileNameError {
  fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
    match self {
      FileNameError::ContainsSlash(s) =>
        f.write_fmt(format_args!(
            "File names cannot contain slashes, but {:?} does.", s)),
    }
  }
}

impl std::fmt::Display for DirectoryNameError {
  fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
    match self {
      DirectoryNameError::ContainsSlash(s) =>
        f.write_fmt(format_args!(
            "File names cannot contain slashes, but {:?} does.", s)),
    }
  }
}

impl std::fmt::Display for PathError {
  fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
    match self {
      PathError::Parse(s) =>
        f.write_fmt(format_args!("Syntax error in path: {}", s)),
    }
  }
}