From 3df9343412ed9d56ac429a9706b6196fc87f6fb2 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 19 Oct 2015 17:31:13 +0200 Subject: [PATCH] Revert "Add error module for error handling" This reverts commit e9b122f612e48c94bbbdaba2584c40f80f9a9371. --- src/error.rs | 35 ----------------------------------- src/main.rs | 1 - src/module.rs | 44 +++++++++++++++++++++++++++++--------------- 3 files changed, 29 insertions(+), 51 deletions(-) delete mode 100644 src/error.rs diff --git a/src/error.rs b/src/error.rs deleted file mode 100644 index 9b06034a..00000000 --- a/src/error.rs +++ /dev/null @@ -1,35 +0,0 @@ -use runtime::Runtime; - -pub struct ImagErrorBase { - pub shortdesc : String, - pub longdesc : String, -} - -pub trait ImagError<'a> { - fn print(&self, rt: &Runtime); - fn print_long(&self, rt: &Runtime); - fn print_short(&self, rt: &Runtime); -} - -impl<'a> ImagError<'a> for ImagErrorBase { - - fn print(&self, rt: &Runtime) { - if self.longdesc.is_empty() { - let s = format!("Error: {}\n\n{}\n\n", - self.shortdesc, self.longdesc); - rt.print(&s) - } else { - let s = format!("Error: {}\n", self.shortdesc); - rt.print(&s) - } - } - - fn print_short(&self, rt : &Runtime) { - rt.print(&self.shortdesc) - } - - fn print_long(&self, rt : &Runtime) { - rt.print(&self.longdesc) - } - -} diff --git a/src/main.rs b/src/main.rs index b508b7f8..2804f3f3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,6 @@ use runtime::Runtime; use module::Module; mod cli; -mod error; mod runtime; mod module; mod storage; diff --git a/src/module.rs b/src/module.rs index bc9b224a..1c686a51 100644 --- a/src/module.rs +++ b/src/module.rs @@ -1,35 +1,49 @@ use runtime::Runtime; -use error::ImagErrorBase; pub struct ModuleError { - base: ImagErrorBase, - module_name: String, + shortdesc : String, + longdesc : String, } impl ModuleError { - pub fn short(module : &T, short : String) -> ModuleError { - ModuleError::new(module, short, "".to_string()) + pub fn short(short : String) -> ModuleError { + ModuleError::new(short, "".to_string()) } - pub fn new(module : &T, short : String, long : String) -> ModuleError { + pub fn new(short : String, long : String) -> ModuleError { ModuleError { - base: ImagErrorBase { - shortdesc: short, - longdesc: long, - }, - module_name: module.name(), + shortdesc: short, + longdesc: long, } } + pub fn print(&self, rt : &Runtime) { + if self.longdesc.is_empty() { + let s = format!("Error: {}\n\n{}\n\n", + self.shortdesc, self.longdesc); + rt.print(&s) + } else { + let s = format!("Error: {}\n", self.shortdesc); + rt.print(&s) + } + } + + pub fn print_short(&self, rt : &Runtime) { + rt.print(&self.shortdesc) + } + + pub fn print_long(&self, rt : &Runtime) { + rt.print(&self.longdesc) + } + } pub trait Module { - fn new() -> Self; - fn load(&self, &rt : Runtime) -> Self; - fn name(&self) -> String; + fn load(self, &rt : Runtime) -> Self; + fn name(self) -> String; - fn execute(&self, &rt : Runtime) -> Option; + fn execute(self, &rt : Runtime) -> Option; }