Welcome to mirror list, hosted at ThFree Co, Russian Federation.

errors.rs « src - github.com/windirstat/RustyMft.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4dc15479b8b0c6a0159b34061b31aaca4654912a (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
52
53
54
55
56
57
58
59
60
61
62
use std::fmt;
use std::fmt::Display;
use std::io;

#[derive(Debug)]
pub enum ErrorKind {
    IoError,
    InvalidFileSignature,
    InvalidEntrySignature,
    Utf16Error
}

#[derive(Debug)]
pub struct MftError {
    /// Formated error message
    pub message: String,
    /// The type of error
    pub kind: ErrorKind,
    /// Any additional information passed along, such as the argument name that caused the error
    pub info: Option<Vec<String>>,
}

impl MftError{
    #[allow(dead_code)]
    pub fn invalid_file_signature(err: String)->Self{
        MftError {
            message: format!("{}",err),
            kind: ErrorKind::InvalidFileSignature,
            info: Some(vec![]),
        }
    }
    #[allow(dead_code)]
    pub fn invalid_entry_signature(err: String)->Self{
        MftError {
            message: format!("{}",err),
            kind: ErrorKind::InvalidFileSignature,
            info: Some(vec![]),
        }
    }
    #[allow(dead_code)]
    pub fn decode_error(err: String)->Self{
        MftError {
            message: format!("{}",err),
            kind: ErrorKind::Utf16Error,
            info: Some(vec![]),
        }
    }
}

impl From<io::Error> for MftError {
    fn from(err: io::Error) -> Self {
        MftError {
            message: format!("{}",err),
            kind: ErrorKind::IoError,
            info: Some(vec![]),
        }
    }
}

impl Display for MftError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { writeln!(f, "{}", self.message) }
}