1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use std::fmt::Debug;
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(_) => {
print!("[INFO] Runtime finished successfully.");
}
Err(e) => {
println!("[FATAL] Runtime panicked because: {:?}", e);
}
}
}