1use std::fmt::Debug;
4
5use logging;
6
7pub trait Runtime<RuntimeResult, RuntimeError>
11where
12 RuntimeResult: Sized + Debug,
13 RuntimeError: Sized + Debug,
14{
15 type Component;
16 fn on_start(&mut self);
17 fn on_stop(&mut self);
18 fn run(self) -> Result<RuntimeResult, RuntimeError>;
19}
20
21pub fn start_runtime<R: Sized + Debug, E: Sized + Debug, T: Runtime<R, E>>(
23 runtime: T,
24) {
25 let runtime_result = runtime.run();
26 match runtime_result {
27 Ok(_) => {
28 logging::info!("Runtime finished successfully.");
29 }
30 Err(e) => {
31 logging::fatal!("Runtime panicked because: {:?}", e);
32 }
33 }
34}