Add ModuleError
This commit is contained in:
parent
7036f93936
commit
911384331b
1 changed files with 44 additions and 6 deletions
|
@ -1,19 +1,57 @@
|
|||
use runtime::Runtime;
|
||||
use std::error::Error;
|
||||
use std::fmt::Formatter;
|
||||
use std::fmt::Result as FMTResult;
|
||||
use std::fmt::Display;
|
||||
use std::path::Path;
|
||||
use std::result::Result;
|
||||
|
||||
use module::todo::TodoModule;
|
||||
|
||||
mod todo;
|
||||
|
||||
pub trait Module {
|
||||
#[derive(Debug)]
|
||||
pub struct ModuleError {
|
||||
desc: String,
|
||||
}
|
||||
|
||||
fn new(&rt : Runtime) -> Self;
|
||||
fn callnames() -> &'static [str];
|
||||
fn name(&self) -> &'static str;
|
||||
impl ModuleError {
|
||||
fn mk(desc: String) -> ModuleError {
|
||||
ModuleError {
|
||||
desc: desc,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn execute(&self, &rt : Runtime) -> Option<Error>;
|
||||
fn shutdown(&self, &rt : Runtime) -> Option<Error>;
|
||||
impl Error for ModuleError {
|
||||
|
||||
fn description(&self) -> &str {
|
||||
&self.desc[..]
|
||||
}
|
||||
|
||||
fn cause(&self) -> Option<&Error> {
|
||||
None
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl Display for ModuleError {
|
||||
fn fmt(&self, f: &mut Formatter) -> FMTResult {
|
||||
write!(f, "ModuleError: {}",
|
||||
self.description())
|
||||
}
|
||||
}
|
||||
|
||||
pub type ModuleResult = Result<(), ModuleError>;
|
||||
|
||||
pub trait Module {
|
||||
|
||||
fn new(rt : &Runtime) -> Self;
|
||||
fn callnames() -> &'static [&'static str];
|
||||
fn name(&self) -> &'static str;
|
||||
|
||||
fn execute(&self, rt : &Runtime) -> ModuleResult;
|
||||
fn shutdown(&self, rt : &Runtime) -> ModuleResult;
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue