imag/src/module/mod.rs

60 lines
1.2 KiB
Rust
Raw Normal View History

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;
use std::result::Result;
2015-10-19 15:54:32 +00:00
2015-11-10 18:27:54 +00:00
use storage::backend::{StorageBackend, StorageBackendError};
2015-11-10 18:29:18 +00:00
use self::command::ExecutableCommand;
2015-11-10 18:27:54 +00:00
mod command;
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 {
2015-10-25 18:54:54 +00:00
fn mk(desc: &'static str) -> ModuleError {
2015-10-24 16:40:40 +00:00
ModuleError {
2015-10-25 18:54:54 +00:00
desc: desc.to_owned().to_string(),
2015-10-24 16:40:40 +00:00
}
}
}
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())
2015-10-24 16:40:40 +00:00
}
}
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
2015-11-10 18:29:18 +00:00
fn getCommandBuilder<T, F>() -> F
where F: FnOnce(StorageBackend) -> T,
T: ExecutableCommand;
2015-10-19 15:54:32 +00:00
}