From 00d0bbf4ae5ec5ef384c8d28759001c6d44c4aaa Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 20 Dec 2015 13:26:14 +0100 Subject: [PATCH] Add basic interface for BM module --- src/main.rs | 2 +- src/module/bm/mod.rs | 45 ++++++++++++++++++++++++++++++++++++++++++++ src/module/mod.rs | 4 ++-- 3 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 src/module/bm/mod.rs diff --git a/src/main.rs b/src/main.rs index 55eac338..b3d3e620 100644 --- a/src/main.rs +++ b/src/main.rs @@ -41,7 +41,7 @@ fn main() { debug!("Runtime : {:?}", &rt); if let Some(matches) = rt.config.cli_matches.subcommand_matches("bm") { - let res = BM::new(&rt).exec(matches.subcommand_matches("bm")); + let res = BM::new(&rt).exec(matches.subcommand_matches("bm").unwrap()); info!("BM exited with {}", res); } else { info!("No commandline call...") diff --git a/src/module/bm/mod.rs b/src/module/bm/mod.rs new file mode 100644 index 00000000..5316f92b --- /dev/null +++ b/src/module/bm/mod.rs @@ -0,0 +1,45 @@ +use std::fmt::{Debug, Display, Formatter}; +use std::fmt; + +use clap::ArgMatches; + +use runtime::Runtime; +use module::Module; + +pub struct BM<'a> { + rt: &'a Runtime<'a>, +} + +impl<'a> BM<'a> { + + pub fn new(rt: &'a Runtime<'a>) -> BM<'a> { + BM { + rt: rt, + } + } + + fn runtime(&self) -> &Runtime { + &self.rt + } + +} + +impl<'a> Module for BM<'a> { + + fn exec(&self, matches: &ArgMatches) -> bool { + unimplemented!() + } + + fn name(&self) -> &'static str { + "bm" + } +} + +impl<'a> Debug for BM<'a> { + + fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { + write!(fmt, "BM"); + Ok(()) + } + +} diff --git a/src/module/mod.rs b/src/module/mod.rs index 7e2462e1..3c907d78 100644 --- a/src/module/mod.rs +++ b/src/module/mod.rs @@ -11,8 +11,8 @@ use runtime::Runtime; pub mod bm; pub mod helpers; -pub trait Module : Debug { - fn new(rt: &Runtime) -> Self; +pub trait Module<'a> : Debug { fn exec(&self, matches: &ArgMatches) -> bool; + fn name(&self) -> &'static str; }