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

github.com/windirstat/RustyMft.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/errors.rs')
-rw-r--r--src/errors.rs53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/errors.rs b/src/errors.rs
new file mode 100644
index 0000000..769fa94
--- /dev/null
+++ b/src/errors.rs
@@ -0,0 +1,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) }
+}