ntfs_reader/
errors.rs

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 thiserror::Error;

#[derive(Error, Debug)]
pub enum NtfsReaderError {
    #[error("elevation error")]
    ElevationError,
    #[error("io error")]
    IOError(#[from] std::io::Error),
    #[error("binread error")]
    BinReadError(#[from] binread::error::Error),
    #[error("windows error")]
    WindowsError(#[from] WindowsErrorWrapper),
    #[error("unknown")]
    Unknown,
}

#[derive(Debug)]
pub struct WindowsErrorWrapper(windows::core::Error);
impl WindowsErrorWrapper {
    pub fn from_win32() -> WindowsErrorWrapper {
        WindowsErrorWrapper(windows::core::Error::from_win32())
    }
}

impl std::fmt::Display for WindowsErrorWrapper {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "Windows error: {}", self.0)
    }
}
impl std::error::Error for WindowsErrorWrapper {}

pub type NtfsReaderResult<T> = core::result::Result<T, NtfsReaderError>;