Skip to main content

harmos_domain/state/
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::{DecodeError, Kind};
22use crate::DefinitionId;
23
24/* === Constants === */
25
26/* === Macros === */
27
28/* === Type Aliases === */
29
30pub type TransactionDecoder<T> = fn(&DefinitionId, u32, &[u8]) -> Result<Option<T>, DecodeError>;
31pub type Inverse<S, T> = fn(&T, &S) -> Option<T>;
32
33/* === Structs === */
34
35pub struct TransactionDefinitions<S, T> {
36    pub definitions: Vec<(Kind, DefinitionId, u32)>,
37    pub decode: TransactionDecoder<T>,
38    pub inverses: Inverse<S, T>,
39}
40
41pub struct RecordDefinitions<R> {
42    pub definitions: Vec<(Kind, DefinitionId, u32)>,
43    pub marker: std::marker::PhantomData<fn() -> R>,
44}
45
46/* === Enums === */
47
48/* === Traits === */
49
50/* === Implementations === */
51
52impl<S, T> Clone for TransactionDefinitions<S, T> {
53    fn clone(&self) -> Self {
54        Self {
55            definitions: self.definitions.clone(),
56            decode: self.decode,
57            inverses: self.inverses,
58        }
59    }
60}
61
62impl<R> Clone for RecordDefinitions<R> {
63    fn clone(&self) -> Self {
64        Self {
65            definitions: self.definitions.clone(),
66            marker: std::marker::PhantomData,
67        }
68    }
69}
70
71/* === Public Functions === */
72
73/* === Private Functions === */
74
75/* === Tests === */