Skip to main content

harmos_sdk/operations/
lifecycle.rs

1/* ***
2 *
3 * Harmos
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 *
7 * ***
8 */
9
10/* === Modules === */
11
12/* === Re-Exports === */
13
14pub use harmos_domain::operations::lifecycle::*;
15
16/* === Imports === */
17
18// Standard Library Imports
19
20// Third Party Imports
21
22// Local Imports
23
24/* === Constants === */
25
26/* === Macros === */
27
28/* === Type Aliases === */
29
30/* === Structs === */
31
32/* === Enums === */
33
34/* === Traits === */
35
36/* === Implementations === */
37
38/* === Public Functions === */
39
40// Bind A Plugin's Two Lifecycle Handlers Under Its Own Lifecycle Policy.
41pub fn bind<P, I, S, C>(
42    table: &mut crate::operations::WireTable<C>, resources: std::sync::Arc<I::Resources>,
43) -> Result<(), crate::operations::ServingError>
44where
45    P: Policy,
46    C: Send + Sync + 'static,
47    I: for<'a> crate::operations::Operation<Declaration = Initialize, Context<'a> = &'a C, Endpoints = ()>,
48    S: for<'a> crate::operations::Operation<Declaration = Shutdown, Resources = I::Resources, Context<'a> = &'a C, Endpoints = ()>,
49{
50    let initialize = Descriptor::of_initialize::<P>()?;
51    let shutdown = Descriptor::of_shutdown::<P>()?;
52    table.bind_owned_lifecycle::<I>(std::sync::Arc::clone(&resources), initialize)?;
53    table.bind_owned_lifecycle::<S>(resources, shutdown)
54}
55
56/* === Private Functions === */
57
58/* === Tests === */