Skip to main content

harmos_sdk/plugin/
mod.rs

1/* ***
2 *
3 * Harmos
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 *
7 * ***
8 */
9
10/* === Modules === */
11
12mod owner;
13
14/* === Re-Exports === */
15
16pub use crate::error::Error;
17pub use harmos_domain::plugin::*;
18pub use owner::{Owner, Table};
19
20/* === Imports === */
21
22// Standard Library Imports
23use std::future::Future;
24use std::pin::Pin;
25use std::sync::Arc;
26
27// Third Party Imports
28
29// Local Imports
30use crate::operations::{ServingError, WireTable};
31use harmos_domain::model::operations::lifecycle;
32
33/* === Constants === */
34
35/* === Macros === */
36
37/* === Type Aliases === */
38
39/* === Structs === */
40
41/* === Enums === */
42
43/* === Traits === */
44
45pub trait Context: crate::lifecycle::Context<Configuration = WireTable> {
46    fn assign_operations(&self, bytes: &[u8]) -> Result<(), ServingError>;
47    fn with_generation(&self, token: [u8; 32]) -> Self;
48}
49
50pub trait Plugin: crate::Lifecycle<Context: Context> + lifecycle::Policy + Sync {
51    const CATALOGS: &'static [crate::operations::Catalog];
52
53    fn register(_registrar: &mut crate::Registrar) -> Result<(), crate::RegistrationError> {
54        Ok(())
55    }
56
57    fn attachment(&self) -> Option<Arc<dyn Attachment<Self::Context>>> {
58        None
59    }
60}
61
62pub trait Attachment<C>: Send + Sync + 'static {
63    #[doc(hidden)]
64    fn bind(self: Arc<Self>, table: &mut WireTable) -> Result<(), ServingError>;
65
66    fn observers(&self) -> Vec<crate::inventory::observers::Declaration>;
67    fn quiesce(&self) -> Pin<Box<dyn Future<Output = Result<(), ServingError>> + Send + '_>>;
68}
69
70/* === Implementations === */
71
72impl crate::lifecycle::Context for () {
73    type Configuration = WireTable;
74}
75
76impl Context for () {
77    fn assign_operations(&self, bytes: &[u8]) -> Result<(), ServingError> {
78        if bytes.is_empty() { Ok(()) } else { Err(ServingError::Catalog) }
79    }
80    fn with_generation(&self, _: [u8; 32]) -> Self {}
81}
82
83/* === Public Functions === */
84
85/* === Private Functions === */
86
87/* === Tests === */