Skip to main content

harmos_operations/
lib.rs

1/* ***
2 *
3 * Harmos
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 *
7 * ***
8 */
9
10/* === Modules === */
11
12#[cfg(feature = "runtime")]
13mod error;
14pub mod host;
15pub mod lifecycle;
16pub mod storage;
17pub mod streams;
18pub mod operations {
19    pub use harmos_domain::operations::*;
20    #[cfg(feature = "lifecycle")]
21    pub use harmos_sdk::operations::{Catalog, Executable, OperationCatalog};
22}
23#[doc(hidden)]
24pub mod __private {
25    pub use harmos_domain::__private::*;
26    #[cfg(feature = "lifecycle")]
27    pub use harmos_sdk::__private::RegistrationBatch;
28}
29
30/* === Re-Exports === */
31
32#[cfg(feature = "runtime")]
33pub use error::Error;
34pub use harmos_domain::*;
35pub use harmos_macros::{catalog, operation};
36
37#[cfg(feature = "lifecycle")]
38pub use harmos_sdk::{Context, Dependent, Executable, ExecutionContext, Operation, Resource, ResourceError, Response};
39pub use host::Host;
40pub use lifecycle::Lifecycle;
41pub use storage::Storage;
42pub use streams::Streams;
43
44/* === Imports === */
45
46// Standard Library Imports
47
48// Third Party Imports
49extern crate self as harmos;
50
51// Local Imports
52#[cfg(feature = "runtime")]
53use harmos_sdk::__private::RegistrationBatch;
54
55/* === Constants === */
56
57#[cfg(feature = "runtime")]
58static BUILTIN_DECLARATIONS: [catalog::Node<operations::WireDeclaration>; 6] = [
59    catalog::Node::Nested(Host::CATALOG.declarations),
60    catalog::Node::Nested(Lifecycle::CATALOG.declarations),
61    catalog::Node::Nested(Storage::CATALOG.declarations),
62    catalog::Node::Nested(Streams::CATALOG.declarations),
63    catalog::Node::Leaf(operations::WireDeclaration::of::<lifecycle::Initialize>()),
64    catalog::Node::Leaf(operations::WireDeclaration::of::<lifecycle::Shutdown>()),
65];
66
67#[cfg(feature = "runtime")]
68static BUILTIN_CALLEES: [catalog::Node<&'static [operations::WireDeclaration]>; 4] = [
69    catalog::Node::Nested(Host::CATALOG.callees),
70    catalog::Node::Nested(Lifecycle::CATALOG.callees),
71    catalog::Node::Nested(Storage::CATALOG.callees),
72    catalog::Node::Nested(Streams::CATALOG.callees),
73];
74
75/* === Macros === */
76
77/* === Type Aliases === */
78
79#[cfg(feature = "runtime")]
80pub type Result<T> = std::result::Result<T, Error>;
81
82/* === Structs === */
83
84pub struct Builtins;
85
86/* === Enums === */
87
88/* === Traits === */
89
90/* === Implementations === */
91
92impl Builtins {
93    pub fn catalog() -> Vec<harmos_domain::OperationDefinition> {
94        let mut definitions = Host::catalog();
95        definitions.extend(Lifecycle::catalog());
96        definitions.extend(Storage::catalog());
97        definitions.extend(Streams::catalog());
98        definitions.push(lifecycle::Initialize::definition());
99        definitions.push(lifecycle::Shutdown::definition());
100        definitions
101    }
102}
103
104#[cfg(feature = "runtime")]
105impl harmos_sdk::operations::OperationCatalog for Builtins {
106    const CATALOG: harmos_sdk::operations::Catalog =
107        harmos_sdk::operations::Catalog::of::<Self>("harmos.builtins", &BUILTIN_DECLARATIONS, &BUILTIN_CALLEES);
108
109    fn batch() -> RegistrationBatch {
110        let mut batch = Host::batch();
111        batch.operations.extend(Lifecycle::batch().operations);
112        batch.operations.extend(Storage::batch().operations);
113        batch.operations.extend(Streams::batch().operations);
114        batch.operations.extend(RegistrationBatch::new().operation::<lifecycle::Initialize>().operations);
115        batch.operations.extend(RegistrationBatch::new().operation::<lifecycle::Shutdown>().operations);
116        batch
117    }
118}
119
120/* === Public Functions === */
121
122/* === Private Functions === */
123
124/* === Tests === */