pars_core/
lib.rs

1pub mod clipboard;
2pub mod config;
3pub mod constants;
4pub mod git;
5pub mod operation;
6pub mod pgp;
7pub mod util;
8
9use std::error::Error;
10use std::fmt::Display;
11use std::path::Path;
12
13#[allow(dead_code)]
14#[derive(Debug)]
15enum IOErrType {
16    PathNotExist,
17    InvalidPath,
18    InvalidName,
19    CannotGetFileName,
20    InvalidFileType,
21    ExpectFile,
22    ExpectDir,
23    PathNotInRepo,
24}
25
26#[derive(Debug)]
27struct IOErr {
28    err_type: IOErrType,
29    path: Box<Path>,
30}
31
32impl IOErr {
33    pub fn new(err_type: IOErrType, path: &Path) -> Self {
34        Self { err_type, path: Box::from(path.to_path_buf()) }
35    }
36}
37
38impl Display for IOErr {
39    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
40        use IOErrType::*;
41        match self.err_type {
42            PathNotExist => write!(f, "Path not exist: {:?}", self.path),
43            CannotGetFileName => write!(f, "Cannot get file name: {:?}", self.path),
44            InvalidPath => write!(f, "Invalid path: {:?}", self.path),
45            InvalidName => write!(f, "Invalid name: {:?}", self.path),
46            InvalidFileType => write!(f, "Invalid file type: {:?}", self.path),
47            ExpectFile => write!(f, "Expect'{:?}' to be a file", self.path),
48            ExpectDir => write!(f, "Expect '{:?}' to be a directory ", self.path),
49            PathNotInRepo => write!(f, "Path '{:?}' not belong to repo", self.path),
50        }
51    }
52}
53
54impl Error for IOErr {}