Skip to main content

harmos_sdk/operations/
catalog.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
17
18// Third Party Imports
19
20// Local Imports
21use super::{Contract, ContractError, Contracts, Declarations, Definition, Entry, WireDeclaration};
22use harmos_domain::Result;
23use harmos_domain::catalog::{Catalog, Member, Visitor};
24
25/* === Constants === */
26
27/* === Macros === */
28
29/* === Type Aliases === */
30
31/* === Structs === */
32
33pub struct AuthoredDeclarations;
34
35pub struct AuthoredContracts;
36
37/* === Enums === */
38
39/* === Traits === */
40
41/* === Implementations === */
42
43impl Visitor for AuthoredDeclarations {
44    type Entry = Entry;
45}
46
47impl<T: super::Operation> Member<T> for AuthoredDeclarations {
48    const ENTRY: Entry = Entry::of::<T::Declaration>();
49}
50
51impl AuthoredDeclarations {
52    pub fn of<C: Catalog<Self>>() -> Result<Vec<Definition>> {
53        Declarations::from_projection(&C::ENTRIES)
54    }
55}
56
57impl Visitor for AuthoredContracts {
58    type Entry = WireDeclaration;
59}
60
61impl<T: super::Operation> Member<T> for AuthoredContracts {
62    const ENTRY: WireDeclaration = WireDeclaration::of::<T::Declaration>();
63}
64
65impl AuthoredContracts {
66    pub fn of<C: Catalog<Self>>() -> std::result::Result<Vec<Contract>, ContractError> {
67        Contracts::from_projection(&C::ENTRIES)
68    }
69}
70
71/* === Public Functions === */
72
73/* === Private Functions === */
74
75/* === Tests === */