use std::fmt::Debug;
use logging;
pub trait Runtime<RuntimeResult, RuntimeError>
where
RuntimeResult: Sized + Debug,
RuntimeError: Sized + Debug,
{
type Component;
fn on_start(&mut self);
fn on_stop(&mut self);
fn run(self) -> Result<RuntimeResult, RuntimeError>;
}
pub fn start_runtime<R: Sized + Debug, E: Sized + Debug, T: Runtime<R, E>>(
runtime: T,
) {
let runtime_result = runtime.run();
match runtime_result {
Ok(_) => {
logging::info!("Runtime finished successfully.");
}
Err(e) => {
logging::fatal!("Runtime panicked because: {:?}", e);
}
}
}