Skip to main content

harmos_runtime/
application.rs

1/* ***
2 *
3 * Harmos
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 *
7 * ***
8 */
9
10/* === Modules === */
11
12/* === Re-Exports === */
13
14/* === Imports === */
15
16// Standard Library Imports
17use std::sync::Arc;
18
19// Third Party Imports
20
21// Local Imports
22use crate::{Handle, Lifecycle, ResourceError};
23
24/* === Constants === */
25
26/* === Macros === */
27
28/* === Type Aliases === */
29
30/* === Structs === */
31
32pub struct Startup<A: Application> {
33    pub runtime: Handle<A>,
34}
35
36/* === Enums === */
37
38/* === Traits === */
39
40pub trait Application: Lifecycle<Context = Startup<Self>> + Sync {
41    type Lanes: crate::operations::Lane;
42
43    type State: Send + Sync + 'static;
44
45    type Transaction: crate::state::Transaction<Self::State, Error: Send + Sync + 'static>
46        + crate::state::TransactionCatalog<Self::State>
47        + Send
48        + Sync
49        + 'static;
50
51    type Record: crate::state::RecordCatalog + Send + Sync + 'static;
52
53    type Streams: Send + Sync + 'static;
54}
55
56/* === Implementations === */
57
58impl<A: Application> Clone for Startup<A> {
59    fn clone(&self) -> Self {
60        Self { runtime: self.runtime.clone() }
61    }
62}
63
64impl<A: Application> harmos_sdk::lifecycle::Context for Startup<A> {
65    type Configuration = crate::runtime::Builder<A>;
66}
67
68impl<A: Application> Startup<A> {
69    pub fn resource<T: Send + Sync + 'static>(&self) -> Result<Arc<T>, ResourceError> {
70        self.runtime.operations.context().resource::<T>()
71    }
72}
73
74/* === Public Functions === */
75
76/* === Private Functions === */
77
78/* === Tests === */