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
use std::path::{Path,PathBuf};
use std::{error,fmt,io};

///
/// `FsTree` error
///
#[derive(Debug)]
pub struct Error {
    entry: PathBuf,
    source: io::Error
}

impl Error {
    pub fn new<P>(entry: P, source: io::Error) -> Error
        where P: AsRef<Path>
    {
        let entry = entry.as_ref().to_path_buf();
        Error { entry, source }
    }
}

impl fmt::Display for Error {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{}: {}", self.entry.to_string_lossy(), self.source)
    }
}

impl error::Error for Error {
    fn source(&self) -> Option<&(dyn error::Error + 'static)> {
        Some(&self.source)
    }
}