2015-10-24 15:46:01 +00:00
|
|
|
use runtime::Runtime;
|
|
|
|
use std::error::Error;
|
2015-10-24 16:40:40 +00:00
|
|
|
use std::fmt::Formatter;
|
|
|
|
use std::fmt::Result as FMTResult;
|
|
|
|
use std::fmt::Display;
|
2015-10-24 15:46:01 +00:00
|
|
|
use std::path::Path;
|
2015-10-24 16:40:40 +00:00
|
|
|
use std::result::Result;
|
2015-10-19 15:54:32 +00:00
|
|
|
|
2015-10-24 15:46:01 +00:00
|
|
|
use module::todo::TodoModule;
|
|
|
|
|
|
|
|
mod todo;
|
2015-10-19 15:54:32 +00:00
|
|
|
|
2015-10-24 16:40:40 +00:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct ModuleError {
|
|
|
|
desc: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ModuleError {
|
|
|
|
fn mk(desc: String) -> ModuleError {
|
|
|
|
ModuleError {
|
|
|
|
desc: desc,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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>;
|
|
|
|
|
2015-10-19 15:54:32 +00:00
|
|
|
pub trait Module {
|
|
|
|
|
2015-10-24 16:40:40 +00:00
|
|
|
fn new(rt : &Runtime) -> Self;
|
|
|
|
fn callnames() -> &'static [&'static str];
|
2015-10-19 16:09:39 +00:00
|
|
|
fn name(&self) -> &'static str;
|
2015-10-19 15:54:32 +00:00
|
|
|
|
2015-10-24 16:40:40 +00:00
|
|
|
fn execute(&self, rt : &Runtime) -> ModuleResult;
|
|
|
|
fn shutdown(&self, rt : &Runtime) -> ModuleResult;
|
2015-10-19 15:54:32 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|