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
|
use std::fmt;
use std::fmt::Display;
use std::io;
#[derive(Debug)]
pub enum ErrorKind {
IoError,
InvalidFileSignature,
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 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) }
}
|