Skip to main content

harmos_sdk/
lifecycle.rs

1/* ***
2 *
3 * Harmos
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 *
7 * ***
8 */
9
10// Shared Application And Plugin Lifecycle
11
12/* === Modules === */
13
14/* === Re-Exports === */
15
16pub use crate::setup::{ApplicationConfiguration, SetupConfiguration};
17
18/* === Imports === */
19
20// Standard Library Imports
21use std::future::Future;
22
23// Third Party Imports
24use serde::de::DeserializeOwned;
25
26// Local Imports
27use crate::setup::Setup;
28
29/* === Constants === */
30
31/* === Macros === */
32
33/* === Type Aliases === */
34
35/* === Structs === */
36
37/* === Enums === */
38
39/* === Traits === */
40
41pub trait Context: Clone + Send + Sync + 'static {
42    #[doc(hidden)]
43    type Configuration: SetupConfiguration;
44}
45
46pub trait Lifecycle: Sized + Send + 'static {
47    type Config: DeserializeOwned + Default + Send + 'static;
48    type Error: std::error::Error + Send + Sync + 'static;
49    type Context: Context;
50
51    fn prepare(config: Self::Config, setup: &mut Setup<Self>) -> impl Future<Output = Result<Self, Self::Error>> + Send;
52    fn initialize(&mut self, context: &Self::Context) -> impl Future<Output = Result<(), Self::Error>> + Send;
53    fn stop(&mut self, context: &Self::Context) -> impl Future<Output = Result<(), Self::Error>> + Send;
54    fn cleanup(&mut self) -> impl Future<Output = Result<(), Self::Error>> + Send;
55}
56
57/* === Implementations === */
58
59/* === Public Functions === */
60
61/* === Private Functions === */
62
63/* === Tests === */