lambda/
runtime.rs

1//! Runtime definition & functions for executing lambda applications.
2
3use std::fmt::Debug;
4
5use logging;
6
7/// A runtime is an important but simple type in lambda that is responsible for
8/// executing the application. The event loop for the application is started
9/// within the runtime and should live for the duration of the application.
10pub 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
21/// Simple function for starting any prebuilt Runnable.
22pub 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}