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
use crate::dpds_path::{Display, Error};
/// Custom error to avoid merging paths of different systems
/// # Example
///```
/// use std::error::Error;
/// use std::io::Read;
/// // Linux
/// use qfile::*;
/// fn example() -> Result<String, Box<dyn Error>> {
///     let (mut file, mut content) = (
///         // returns the type OsPathError
///         QFilePath::add_path("src\\file.rs")?.get_file(Permissions::RW)?,
///         String::new(),
///     );
///     file.read_to_string(&mut content)?;
///     return Ok(content);
/// }
/// fn main() {
///     if let Err(err) = example() {
///         println!("{err}");
///     }
/// }
///```
///
/// ---
/// Output:
///  > You are using the windows path format for Unix. Use `unix` format for the path\
///  > \> ./folder1/folder2/file.txt\
///  > \> ../folder2/file.txt\
///  > \> ./file.txt
///
#[derive(Debug)]

pub enum OsPathError {
    UnixPathIncorrect,
    WindowsPathIncorrect,
    PathIsEmpty,
    SystemNotDefined,
}
impl Error for OsPathError {}
impl Display for OsPathError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match *self {
            OsPathError::UnixPathIncorrect => f.write_str("You are using the windows path format for Unix. Use `unix` format for the path:\n> ./folder1/folder2/file.txt\n> ../folder2/file.txt\n> ./file.txt"),
            OsPathError::WindowsPathIncorrect => f.write_str("You are using the unix path format for Windows. Use `windows` format for the path:\n> .\\folder1\\folder2\\file.txt\n> ..\\folder2\\file.txt\n> .\\file.txt"),
            OsPathError::PathIsEmpty=>f.write_str("The path is empty"),
            OsPathError::SystemNotDefined =>f.write_str(" SystemNotDefined"),
        }
    }
}